Review---Merge sort to find the reverse order--the Garlic 2017noip Simulator Two--the sort of the garlic king

Source: Internet
Author: User

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&LT;=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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.