Y15BeTa @ 2019-08-07 16:20:49
树状数组
开了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 Kevin_Wa @ 2019-08-07 16:21:38
强调妹子?话说高二刚学OI还来得及吗???
by 7KByte @ 2019-08-07 16:21:53
不是这么离散化的吧……
by Y15BeTa @ 2019-08-07 16:22:29
@Gang_Leader 所以......可是蒟蒻不会啊QwQ
by ninedays9九天 @ 2019-08-07 16:22:41
高二的是姐姐吧。。。。。。
by ninedays9九天 @ 2019-08-07 16:23:21
~~还是归并好
by ciwomuli @ 2019-08-07 16:24:10
高二妹子我要了
by Y15BeTa @ 2019-08-07 16:24:29
@ninedays9九天 可我现在只会树状数组(光速逃
by Y15BeTa @ 2019-08-07 16:26:11
说了刚学OI(
所以大家有什么优化不超时的办法吗QwQ
by _yjh @ 2019-08-07 16:28:16
by xyf007 @ 2019-08-07 16:28:25
刚学OI就会树状数组%%%