Title Link: https://nanti.jisuanke.com/t/16443
I don't have a fast power matrix, so I just took 60 points,
Find Merge Sort master is not proficient, take this opportunity to review.
Heavy in the merger of sorting ideas, to remember!
#include <iostream>#include<cstring>using namespacestd;intn,m,a[30005],s[30005],ans,d[30005];voidMsort (intLintR) { if(L==R)return;//If there is only one number to return, this also allows L to be no greater than R, because the L=r returns intMid= (l+r) >>1; Msort (L,mid); Msort (Mid+1, R); intI=l,j=mid+1, k=l; while(i<=mid&&j<=R) { if(d[i]<=D[j]) {S[k]=d[i];k++;i++; } Else{S[k]=d[j];k++;j++; Ans+=mid-i+1;//ans for the number of reverse order, the left sequence from I to mid increment, so from I to mid are greater than J-----------Note } } while(I<=mid) {//no entry into the array is the same as the following functions[k]=d[i];k++;i++; } while(J<=R) {//missing out.s[k]=d[j];k++;j++; } for(inti=l;i<=r;i++) d[i]=s[i];//Row Order}intMain () {CIN>>N; for(intI=1; i<=n;i++) cin>>A[i]; CIN>>m; while(m--){ intL,r; CIN>>l>>R; for(inti=l;i<=r;i++) d[i]=A[i]; Msort (L,R); cout<<ans<<Endl; memset (s),0,sizeof(s)); memset (d,0,sizeof(d)); Ans=0; } return 0;}
Review---Merge sort to find the reverse order--the Garlic 2017noip Simulator Two--the sort of the garlic king