一个简洁的归并排序实现模板
long long merge_sort(int l, int r) { int mid, p, q, i, j, len; if(l >= r) return 0; mid = (l + r) >> 1; len = r - l + 1; p = l; q = mid + 1; j = l; for(i = 0; i < len; ++i) { if((q > r) || (num[p] < num[q] && p <= mid)) { t[j++] = num[p++]; } else { t[j++] = num[q++]; } } for(i = l; i <= r; ++i) num[i] = t[i]; return ans; }