P1908 逆序对 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051//Inverted Sequence Numbers//different from only Merge Sort:"//Diff" #include<bits/stdc++.h>using namespace std;const int MAXn=500000;inline int read(){ register char c; while(c=getchar(),c<'0'||c>'9'); register int x(c-'0'); while(c=getchar(),c>='0'&&c<='9') { x=x*10+c-'0'; } return x;}int n;int a[MAXn+10];int tmp[MAXn+10];long long ans;//Diffvoid merge(int ll, int rr) { if (rr - ll <= 1) { return; } int mid = ll + (rr - ll >> 1); merge(ll, mid); merge(mid, rr); int p = ll, q = mid, s = ll; while (s < rr) { if (p >= mid || (q < rr && a[p] > a[q])) { tmp[s++] = a[q++]; ans += mid - p;//Diff } else { tmp[s++] = a[p++]; } } for (int i = ll; i < rr; i++) { a[i] = tmp[i]; }}int main() { n = read(); for (int i = 0; i < n; i++) { a[i] = read(); } merge(0, n); printf("%lld", ans);//Diff}