奇妙的RE

P1908 逆序对

RainsAFO @ 2019-05-15 17:11:41

#include<iostream>
using namespace std;
long long n,a[50000001];
long long m,ans=0;
long long lowbit(long long k){
    return k&-k;
}
int main(){
    cin>>n;
    for(long long i=1;i<=n;i++){
        cin>>m;
        for(long long j=m;j;j-=lowbit(j))
            ans-=a[j];
            ans+=i-1;
        for(long long j=m;j<=n;j+=lowbit(j))
            a[j]++;
    }
    cout<<ans<<endl;
}

大佬们帮蒟蒻看看吧。。。。。。


by Smile_Cindy @ 2019-05-15 17:14:47

@猪是的念着倒

离散化呢?


|