复习一下了,本题ans会比较大用lld
#include<bits/stdc++.h>
using namespace std;
#define cl(a,b) memset(a,b,sizeof(a))
#define LL long long
#define pb push_back
#define gcd __gcd
#define For(i,j,k) for(int i=(j);i<k;i++)
#define lowbit(i) (i&(-i))
#define _(x) printf("%d\n",x)
const int maxn = 1e5+10;
const int inf = 1 << 28;
LL a[maxn];
LL ans;
LL tmp[maxn];
void merge(int l,int mid,int r){
int i=l,j=mid+1,k=l;
while(i<=mid&&j<=r){
if(a[i]<=a[j]){
tmp[k++] = a[i++];
}
else {
tmp[k++] = a[j++];
ans += mid-i+1;
}
}
while(i<=mid) tmp[k++] = a[i++];
while(j<=r) tmp[k++] = a[j++];
for(int i=l;i<k;i++)a[i] = tmp[i];
}
void merge_sort(int l,int r){
if(l>=r)return ;
int mid = l+r>>1;
merge_sort(l,mid);
merge_sort(mid+1,r);
merge(l,mid,r);
}
int main(){
int n;
while(~scanf("%d",&n)){
for(int i=0;i<n;i++){
scanf("%lld",&a[i]);
}
ans = 0;
merge_sort(0,n-1);
//for(int i=0;i<n;i++)cout<<a[i]<<" ";
printf("%lld\n",ans);
}
return 0;
}