彩笔求助,一片紫色(

P1908 逆序对

Dirge_ @ 2020-07-12 16:03:28

蒟蒻也不知道为什么会RE啊/kk

数组貌似也没有开小,本地运行也没有问题啊,求大佬帮忙QWQ

代码:

#include<bits/stdc++.h>
using namespace std;
long long n,m,i,x,ans,a[5000005];
long long lowbit(long long x)
{
    return x&(-x);
}
void add(long long x)
{
    for(long long k=x;k<=n;k+=lowbit(k)) a[k]++;
}
long long sum(long long x)
{
    long long s=0;
    for(long long q=x;q;q-=lowbit(q)) s+=a[q];
    return s;
}
int main()
{
    scanf("%lld",&n);
    for(i=1;i<=n;i++)
     {
        scanf("%lld",&x); 
        add(x);
        ans+=sum(n)-sum(x);
     }
    printf("%lld",ans);
    return 0;
}

谢谢大家啊啊啊啊(我一定有sb错误


by Dirge_ @ 2020-07-12 16:40:45

@fhh_orz 蟹蟹


by Dirge_ @ 2020-07-12 16:40:53

@KyireIvring 蟹蟹


by Dimly_dust @ 2020-07-12 17:20:32

我来考咕了


by Dirge_ @ 2020-07-14 09:56:51

@Dimly_dust 哈哈哈哈哈哈哈艹(


by Laser_Crystal @ 2020-07-14 09:56:52

我也来考古了


by Dimly_dust @ 2020-07-14 09:58:04

@玉希亚 这捞帖捞的。。。。


by Dirge_ @ 2020-07-14 10:01:07

这帖子现在还有人看?/xyx(就amazing


by Dirge_ @ 2020-07-14 10:01:22

@Lattle_Car 阿这


by Laser_Crystal @ 2020-07-14 10:03:07

@玉希亚 闲,在翻犇犇


by Laser_Crystal @ 2020-07-14 10:03:16

@玉希亚 %%%%%%%%


上一页 | 下一页