标签:排序 ++ div [] inf oid void 逆序对 for
int L[100010]; int R[100010]; void merge(int p[],int l,int mid,int r){ int len1 = mid - l; int len2 = r - mid; for(int i = 0;i < len1; i++){ L[i] = p[l+i]; } L[len1] = INF; for(int i = 0;i < len2; i++){ R[i] = p[mid+i]; } R[len2] = INF; int con1 = 0; int con2 = 0; for(int i = l;i < r; i++){ if(L[con1] < R[con2]){ p[i] = L[con1]; con1++; }else if(L[con1] > R[con2]){ p[i] = R[con2]; con2++; }else{ p[i] = L[con1]; con1++; } } } void mergeSort(int p[],int l,int r){ if(r - l > 1){ int mid = (l+r)/2; mergeSort(p,l,mid); mergeSort(p,mid,r); merge(p,l,mid,r); } }
l表示最左边的数的下标,r-1表示最右边的数的下标。
标签:排序 ++ div [] inf oid void 逆序对 for
原文地址:http://www.cnblogs.com/zhangjiuding/p/7900916.html