aishiteru_mitsu_ha @ 2024-01-18 17:59:33
#include<bits/stdc++.h>
using namespace std;
long long tree[500010],cnt1,cnt2=1,n;
struct node{
int id,num,hash;
}a[500010];
bool cmp1(node x,node y){
return x.id<y.id;
}
bool cmp2(node x,node y){
return x.hash<y.hash
}
int lowbit(int a){
return a&(-a);
}
void update(int a,int b){
while(a<=n){
tree[a]+=b;
a+=lowbit(a);
}
}
int getsum(int a){
int sum=0;
while(a>0){
sum+=tree[a];
a-=lowbit(a);
}
return sum;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].num;
a[i].id=i;
}
sort(a+1,a+n,cmp2);
a[1].hash=1;
for(int i=2;i<=n;i++){
if(a[i].num==a[i-1].num){
a[i].hash=a[i-1].hash;
}else{
a[i].hash=++cnt2;
}
}
sort(a+1,a+n,cmp1);
for(int i=1;i<=n;i++){
update(a[i].hash,1);
}
for(int i=1;i<=n;i++){
cnt1+=getsum(a[i].hash);
}
cout<<cnt1;
return 0;
}
by 云雷心柠檬听 @ 2024-01-18 18:02:37
bool cmp2(node x,node y){
return x.hash<y.hash
}
没加分号
by Hollow_Knight @ 2024-01-18 18:03:06
@not_much 大哥,你要不先在DEV上测测吧,第11行没打;
by Little_x_starTYJ @ 2024-01-18 18:08:42
鸡脖说的对
by Little_x_starTYJ @ 2024-01-18 18:08:49
@qidaimuhuoying
by aishiteru_mitsu_ha @ 2024-01-18 18:11:33
过编译了,全wa
by aishiteru_mitsu_ha @ 2024-01-18 18:12:22
@qidaimuhuoying 当前环境(物理意义)不太允许
by fried_chicken @ 2024-01-18 19:00:59
@not_much 在机房敲的是吧(