Z_Ovids @ 2019-07-30 18:18:48
直接上代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mx=500005;
long long cnt=0,n,a[mx],b[mx];
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
b[a[i]]=i;
}
sort(a+1,a+1+n);
for(int i=1;i<=n;i++){
if(b[a[i]]!=n)
cnt+=abs(b[a[i]]-i);
}
cout<<cnt;
return 0;
}
by Z_Ovids @ 2019-07-31 08:50:15
@人间失格 树状数组感觉学了跟没学一样