1 #include2 #include 3 4 int a[1000004],tmp1[500002],tmp2[500002]; 5 long long cnt; 6 void merge(int start,int mid,int end){ 7 int i,j,k; 8 for(k=0,i=start; i<=mid; i++) 9 tmp1[k++]=a[i];10 tmp1[k]=0x7fffffff;11 for(k=0,i=mid+1; i<=end; i++)12 tmp2[k++]=a[i];13 tmp2[k]=0x7fffffff;14 for(i=j=0,k=start; k<=end; k++){15 if(tmp1[i]<=tmp2[j]){16 a[k]=tmp1[i++];17 }else{18 a[k]=tmp2[j++];19 cnt+=mid-start+1-i; 20 }21 }22 }23 24 void mergeSort(int start,int end){25 if(start