为什么50分?

P1908 逆序对

樱花飞舞 @ 2019-07-13 11:41:23

#include<cstdio>
#include<algorithm>
#define lowbit(x) ((x)&(-x))
const int N = 900005;
int c[N],n,a[N],b[N];
void add(int x,int k)
{
    while(x<=n)
    {
        c[x]+=k;
        x+=lowbit(x);
    }
}
int get_sum(int x)
{
    int sum=0;
    while(x>0)
    {
        sum+=c[x];
        x-=lowbit(x);
    }
    return sum;
}
inline bool cmp(int x,int y)
{
    return a[x]!=a[y]?a[x]>a[y]:x>y;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        b[i]=i;
    }
    std::sort(b+1,b+1+n,cmp);
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        add(b[i],1);
        sum+=get_sum(b[i]-1);
    }
    printf("%d",sum);
}

by DriverBen @ 2019-07-13 11:46:31

int->long long

by SSerxhs @ 2019-07-13 11:50:03

不开ll见祖宗


by 固执 @ 2019-07-23 10:45:45

typedef long long ll;
ll 变量;

|