jess1ca1o0g3 @ 2023-08-18 10:42:28
#include<cstdio>
using namespace std;
int n,a[10000005],b[10000005];
long long ans=0;
void ms(int l,int r){
if(l>=r) return;
int mid=(l+r)/2,i=l,j=mid+1,k=l;
ms(l,mid);
ms(mid+1,r);
while(i<=mid&&j<=r){
if(a[i]<a[j])
b[k++]=a[i++];
else{
b[k++]=a[j++];
ans+=mid-i+1;
}
}
while(i<=mid) b[k++]=a[i++];
while(j<=r) b[k++]=a[j++];
for(int p=l;p<=r;p++)
a[p]=b[p];
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
ms(1,n);
printf("%lld",ans);
return 0;
}
找不出来问题,求解
by jess1ca1o0g3 @ 2023-08-18 10:43:12
不对,是30分
by zbyzby666 @ 2023-08-18 10:44:46
看不懂