pujingcat @ 2021-11-27 13:23:25
某神犇的树状数组的不开O2的200多ms,我开O2最慢的点500多ms 神犇说我码丑了,求助哪里码丑了
#include <bits/stdc++.h>
#define lowbit(x) x&-x
#define N 500001
#define int long long
using namespace std;
int n,ans=0,tot=1,sp;
int p[N],tr[N];
struct fuck {
int w,bh;
} sb[N];
map<int,int> lsh;
bool cmp(fuck a,fuck b) {
return a.w<b.w;
}
void change(int xx,int y) {
int x=xx;
while(x<=n) {
tr[x]+=y;
x+=lowbit(x);
}
}
int ask(int xx) {
int sum=0,x=xx;
while(x) {
sum+=tr[x];
x-=lowbit(x);
}
return sum;
}
signed main() {
scanf("%d",&n);
sp=n;
for(int i=1; i<=n; i++) {
scanf("%d",&sb[i].w);
sb[i].bh=i;
lsh[i]=0;
}
sort(sb+1,sb+1+n,cmp);
for(int i=1; i<=n; i++) {
if(lsh[sb[i].w]==lsh.end) lsh[sb[i].w]=tot,tot++;
p[sb[i].bh]=lsh[sb[i].w];
}//离散化
for(int i=1; i<=n; i++) change(p[i],1);
for(int i=n; i>=1; i--) {
ans+=(sp-ask(p[i]));
change(p[i],-1);
sp--;
}
printf("%d",ans);
return 0;
}
by NaCly_Fish @ 2021-11-27 13:25:20
离散化用 map 可还行
by 404Not_Found @ 2021-11-27 13:26:57
离散化用 map 可还行
by Chancylaser @ 2021-11-27 13:30:07
/jk/jk
by ZJBZJB @ 2021-11-27 20:46:32
您都sort了还用什么map啊
by Liquefyx @ 2022-02-08 15:06:01
map离散化是有什么怪癖么¯_(ツ)_/¯
by pujingcat @ 2022-05-05 19:11:35
@CE_Automata 因为我比较强啊