Look at the test instructions: [1,i] is equal to the number of a[i] is greater than [, JN] equals A[j] number and i<j, how much to this (i,j), i<j but I front of the legal number is greater than J after the look very like the reverse number, so very easy to go to the tree array , but the treatment on the individual, as I was dealing with the game is very troublesome, although made but also spend more time, after jiege education, in fact, is in the tree-like array in reverse to find can be, gray often simple clear, affixed to commemorate my rubbing ratio ...
int N;int aa[1000000 + 55];int bb[1000000 + 55];int c[1000000 + 55];map<int, int >mp;ll lowbit (ll x) {return x& ( -X);} void Add (int i,int val) {while (I <= N) {c[i] + = Val;i + lowbit (i);}} ll get_sum (int i) {ll sum = 0;while (i) {sum + = c[i];i-= Lowbit (i);} return sum;} void Init () {memset (c,0,sizeof (c)); Memset (aa,0,sizeof (AA)); memset (Bb,0,sizeof (BB)); Mp.clear ();} int main () {while (scanf ("%d", &n) = = 1) {init (); for (int. i=1;i<=n;i++) scanf ("%d", &aa[i]); for (int i=1;i<=n ; i++) {Mp[aa[i]]++;bb[i] = Mp[aa[i]];add (bb[i],1);} Mp.clear (); ll ans = 0ll;for (int i=n;i>=1;i--) {Add (bb[i],-1); Mp[aa[i]]++;int tmp = Mp[aa[i]];ans + = i-get_sum (tmp)- 1;} Cout<<ans<<endl;} return 0;}
Codeforces Round #261 (Div. 2) D tree-like array application