RE爆0,求助

P1908 逆序对

yonghang @ 2023-03-23 13:49:06

#include<bits/stdc++.h>
using namespace std;
int a[1000010];
int c[1000010];
int n,m;
int lowbit(int x){
    return x&-x;
}
void add(int x)
{
    while(x<=100010)
    {
        c[x]++;
        x+=lowbit(x);
    }
}
long long summ(int x)
{
    long long ans=0;
    while(x>0)
    {
        ans+=c[x];
        x-=lowbit(x);
    }
    return ans;
}
int main()
{
    long long ha=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        a[i]++;
    }
    for(int i=n;i>=1;i--)
    {
        ha+=summ(a[i]-1);
        add(a[i]);
    }
    printf("%lld",ha);
}

by Imiya @ 2023-03-23 14:20:27

@yonghang

序列中每个数字不超过 10^9


by xuzirui_2 @ 2023-07-14 15:10:25

这个题要long long 的大哥


|