sel_fish @ 2019-11-14 18:14:19
rt,求大佬解答
#include<cstdio>
#include<cstring>
#define re register int
using namespace std;
typedef long long ll;
const int maxn=510000;
ll ans;
int n,A[maxn],c[maxn];
inline int read() {
int x=0,cf=1;
char ch=getchar();
while(ch<'0'||ch>'9') {
if(ch=='-') cf=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9') {
x=(x<<3)+(x<<1)+(ch^48);
ch=getchar();
}
return x*cf;
}
int query(int x) {
int res=0;
for(;x;x-=x&-x) res+=c[x];
return res;
}
void add(int x,int v) {
for(;x<=500000;x+=x&-x) c[x]+=v;
}
int main() {
n=read();
for(re i=1;i<=n;i++) A[i]=read();
for(re i=1;i<=n;i++) {
add(A[i],1);
ans+=i-query(A[i]);
}
printf("%lld",ans);
return 0;
}
by 老部长 @ 2019-11-14 18:14:47
为什么你不强调自己是妹子
by sel_fish @ 2019-11-14 18:15:20
上面是我的机房沙雕同桌,请不要复读
by 超级小周 @ 2019-11-14 18:15:29
第二行n个数,表示给定的序列。序列中每个数字不超过
by momo5440 @ 2019-11-14 18:16:15
a的值可能为1e9
by sel_fish @ 2019-11-14 18:16:40
哦,谢谢大佬 @超级小周
by Smile_Cindy @ 2019-11-14 18:17:03
@sel_fish
const int maxn=510000;
序列中每个数字不超过
by 蒟蒻小鸽鸽 @ 2019-11-14 18:17:34
为什么你不强调自己是妹子
by sel_fish @ 2019-11-14 18:18:38
感谢各位大佬,不能用树状数组A这道题,改成1e9后本地运行错误
by sel_fish @ 2019-11-14 18:19:42
好像题解中有,但是我不会,还是安心打归并吧
by Hzao @ 2019-11-14 18:24:33
@sel_fish 离散化啊!