归并排序,模型如下:
if low<high
then mid<-[n/2]
call mergesort(low,mid);
call mergesort(mid+1,high);
call merge(low,mid,high);
endif
end mergesort
示例程序:
[cpp]
#include <iostream>
using namespace std;
long long cnt;
int a[1000010];
void merge(int s1,int e1,int s2,int e2)
{
int p1=s1,p2=s2,p=0,*t;
t=new int[e2-s1+5];
while(p1<=e1&&p2<=e2)
{
if(a[p...