hammp @ 2022-06-25 21:36:21
#include<stdio.h>
int merge(int *a,int *temp,int left,int c,int right){
int i,j;
long long n=0;
int k=left;
i=left,j=c+1;
while(i<=c&&j<=right){
if(a[i]>a[j]){
temp[k++]=a[j++];
n += c+1-i;
}
else{
temp[k++]=a[i++];
}
}
while(i<=c)
temp[k++]=a[i++];
while(j<=right)
temp[k++]=a[j++];
for(int i=left;i<=right;i++)
a[i]=temp[i];
return n;
}
int Nixudui(int *a,int *temp,int left,int right){
long long n=0;
int c;
if(left==right)
return 0;
else{
c = (left+right)/2;
n += Nixudui(a,temp,left,c);
n += Nixudui(a,temp,c+1,right);
n += merge(a,temp,left,c,right);
return n;
}
}
int main(){
int n;
long long num;
scanf("%d",&n);
int a[n],temp[n];
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
num=Nixudui(a,temp,0,n-1);
printf("%lld",num);
}
by Eason2009 @ 2022-06-25 21:40:16
n += c+1-i;
应为
n += (long long)(c+1-i);
by StarLbright40 @ 2022-06-25 21:42:59
这个没影响吧/yiw
by hammp @ 2022-06-26 11:41:49
@Eason2009 试过了,还是不行。
by Lelouch_J @ 2022-07-06 21:33:52
楼主解决了吗,我也50后面全re