In fact, the first time the teacher taught me is to teach the merger.
Thought about it tonight. You can use a tree array to maintain the prefix and do it.
First sort the discretization out of the coordinates, in order to add the number of I, query the front of the number of larger than it, is the inverse number of the
# include <iostream># include<cstdio># include<cstring># include<algorithm>using namespacestd;intsum[100002];inta[100002],b[100002],n;intLowbit (intk) { returnK &-K;}voidUpdata (intKintdata) { while(k <=N) {Sum[k]+=data; K+=Lowbit (k); }}intSum (intk) { intAns =0; while(k) {ans+=Sum[k]; K-=Lowbit (k); } returnans;}intMain () {scanf ("%d",&N); for(inti =1; I <= n;i++) {scanf ("%d",&A[i]); B[i]=A[i]; } sort (b+1, B + n +1); intAns =0; for(inti =1; I <= n;i++){ intK = Lower_bound (b +1, B + n +1, A[i])-b; Updata (k,1); Ans+ = i-Sum (k); } printf ("%d\n", ans);}
Inverse number pairs statistics (tree array + discretization)