彩笔求助,一片紫色(

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 ezoixx130 @ 2020-07-12 16:05:08

@玉希亚 每个数可能达到 10^9,不能直接扔进树状数组里。


by Callous_Murder @ 2020-07-12 16:05:21

模板调出来了?


by _Floyd_ @ 2020-07-12 16:05:34

bit过不了的哎


by Dirge_ @ 2020-07-12 16:06:37

@ezoixx130 谢谢QAQ(捕捉ez!


by Dirge_ @ 2020-07-12 16:06:52

@Callous_Murder 嗯(


by 引领天下 @ 2020-07-12 16:07:10

一片紫色?打算钓一堆管理?


by Dirge_ @ 2020-07-12 16:07:24

@Floyd QAQ?(我能说我听不懂吗


by Dirge_ @ 2020-07-12 16:08:11

@引领天下 啊这 然而并没有啊


by IntrepidStrayer @ 2020-07-12 16:32:47

@玉希亚 先离散化


by Cripple_Abyss @ 2020-07-12 16:35:50

map?


| 下一页