#大佬求助#

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 IntrepidStrayer @ 2020-07-19 11:12:36

orz 大佬


by 1saunoya @ 2020-07-19 11:12:44

你没有离散化。。


by IntrepidStrayer @ 2020-07-19 11:13:02

ai<=1e9要离散化


by Integricode_26 @ 2020-07-19 11:16:45

@骚气呀 这题考察的是归并排序


by Skies @ 2020-07-19 11:16:47

谢谢


by critnos @ 2020-07-19 11:17:01

离散化

long long


by critnos @ 2020-07-19 11:17:14

@陈照然666 ?树状数组不行?


by critnos @ 2020-07-19 11:17:56

?树状数组会 TLE?


by Skies @ 2020-07-19 11:18:09

@陈照然666 可以用树状数组


by chen_zhe @ 2020-07-19 11:18:43

@陈照然666 树状数组为什么不行?


| 下一页