int c[LEN],d[LEN],summ=0;
void MergeSort(int p, int r)
{
if (p >= r) return ;
int i, j, v, mid = (p + r) >> 1;
MergeSort(p, mid);
MergeSort(mid + 1, r);
i = p; j = mid + 1; v = 0;
while (i <= mid && j <= r) {
if (c[i] > c[j]) {
d[v++] = c[j++];
summ += mid - i + 1; //inversion
}
else d[v++] = c[i++];
}
while (i <= mid) d[v++] = c[i++];
memcpy(c + p, d, v * sizeof(int));
}
借助归并排序可以求你序