inline void mergesort(int L,int R){ int M=(L+R)>>1; if(M>L) mergesort(L,M); if(M+1<R) mergesort(M+1,R); int k=L,t1=L,t2=M+1; while(t1<=M && t2<=R){ if(b[t1]<=b[t2]){ p[k++]=b[t1++]; } else{ ans+=(M-t1+1); p[k++]=b[t2++]; } } while(t1<=M) p[k++]=b[t1++]; while(t2<=R) p[k++]=b[t2++]; fo(i,L,R) b[i]=p[i]; }
最经典就是求逆序对吧,比数据结构去维护实际上是要快多的