_SkyDream_ @ 2022-08-31 13:36:55
#include <bits/stdc++.h>
using namespace std;
int n,a[100010],tmp[100010];
long long ans;
void merge_sort(int l,int r)
{
if (l==r) return;
int mid=(l+r)/2,p,i,j;
merge_sort(l,mid);
merge_sort(mid+1,r);
p=0; i=l; j=mid+1;
while (i<=mid&&j<=r)
if (a[i]<=a[j])
tmp[p++]=a[i++];
else {
ans+=mid-i+1;
tmp[p++]=a[j++];
}
while (i<=mid) tmp[p++]=a[i++];
while (j<=r) tmp[p++]=a[j++];
memcpy(a+l,tmp,sizeof(int)*(r-l+1));
}
int main()
{
cin>>n;
for (int i=0;i<n;++i) scanf("%d",&a[i]);
merge_sort(0,n-1);
cout<<ans<<endl;
return 0;
}
有谁告诉我这为甚会RE
by 02Ljh @ 2022-08-31 13:37:55
@horray_for_bfs_dfs
by _SkyDream_ @ 2022-08-31 13:38:55
@02Ljh 谢谢
by AzureMist @ 2022-09-12 11:23:40
@horray_for_bfs_dfs 您是不是没看到