#大佬求助#

P1908 逆序对

Skies @ 2020-07-19 11:09:06

#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
int a[N],c[N];
int n;
int ask(int x)
{
    int ans=0;
    for(;x>0;x-=x&-x)ans+=c[x];
    return ans;
}

void add(int x,int y)
{
    for(;x<=n;x+=x&-x)c[x]+=y;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
//      add(i,1);
    }
    int ans=0;
    for(int i=n;i>0;i--)
    {
        ans+=ask(a[i]-1);
        add(a[i],1);
    }
    cout<<ans;
    return 0;
}

all RE,help!!!


by k3v1n070828 @ 2020-07-19 11:35:32

大佬求助

orz


by IceYukino @ 2020-07-19 11:51:50

大佬求助!=求助大佬

说明lz是大佬


by 晨光万丈 @ 2020-07-19 12:46:53

树状数组需优化


by 晨光万丈 @ 2020-07-19 12:47:36

树状数组洛谷是不太支持的


by 晨光万丈 @ 2020-07-19 12:48:42

@骚气呀


by Suuon_Kanderu @ 2020-07-19 13:07:58

@洛谷检察员 ?smwy?什么叫树状数组luogu不支持?


by Skies @ 2020-07-19 14:10:01

@洛谷检察员 我A了


by Suuon_Kanderu @ 2020-07-19 14:10:44

我也A了啊


by 方123456 @ 2020-07-19 16:43:35

luogu 原来不支持 树状数组?


by 晨光万丈 @ 2020-07-19 17:05:06

@骚气呀 哪你一定优化了


上一页 |