Y15BeTa @ 2019-08-07 15:47:18
树状数组
开了longlong
用了读入优化
TLE
50pts
#include<cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#define int long long
using namespace std;
typedef long long ll;
inline void input(ll &x){
ll ans=0,f=1;
char c=getchar();
while(c>'9'||c<'0'){
if(c=='-')f=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
ans=ans*10+c-48;
c=getchar();
}
x=ans*f;
}
inline void output(ll x){
if(x<0)x=-x,putchar('-');
if(x>9)output(x/10);
putchar(x%10+48);
}
inline void writeln(ll x){
output(x);
putchar('\n');
}
int a[5000005],b[5000005],c[20000005],n,cnt;
map<int,int> sign;
inline int lowbit(int x){return x&(-x);}
inline void add(int k){
while(k<=n){
c[k]++;
k+=lowbit(k);
}
}
inline int query(int k){
int ans=0;
while(k){
ans+=c[k];
k-=lowbit(k);
}
return ans;
}
signed main(){
input(n);
for(int i=1;i<=n;i++){
input(a[i]);b[i]=a[i];
}
sort(b+1,b+n+1);
for(int i=1;i<=n;i++){
sign[b[i]]=++cnt;
}
int ans=0;
for(int i=n;i>=1;i--){
ans+=query(sign[a[i]]-1);
add(sign[a[i]]);
}
writeln(ans);
}
by Y15BeTa @ 2019-08-07 15:48:03
加了离散化(逃
by Jason_Lee @ 2019-08-07 15:49:52
你以为你是汉子我就救了吗qaq
by 迷失再黑夜里 @ 2019-08-07 15:54:13
无语
by Y15BeTa @ 2019-08-07 15:55:33
没有人救我呀QwQ
我女装给你们看
by mendessy @ 2019-08-07 15:57:27
先女装啊
by Froshine @ 2019-08-07 16:02:49
@TwxAqu 那女装之前更加没人救了