Using a tree-like array to find the only pit point is the sum to use a long long to save the code directly after forgetting can also directly see 2333 ...
PS: And the hdu3743 code is the same, because two are reverse to the template problem ...
1#include <stdio.h>2#include <string.h>3#include <algorithm>4 using namespacestd;5 ints[500005];6 intN;7 structnum{8 intXuhao,num;9}nu[500005];Ten intQufan (inti) { One returni& (-i); A } - intcmp (num nu1,num nu2) { - returnnu1.num<Nu2.num; the } - intSumminta) { - intsum=0; - while(a>0){ +sum+=S[a]; -a-=Qufan (a); + } A returnsum; at } - voidhahaintNintx) { - while(x<=N) { -s[x]++; -x+=Qufan (x); - } in } - intMain () { to intN; + while(~SCANF ("%d", &n) &&N) { - for(intI=1; i<=n;i++){ thescanf"%d",&nu[i].num); *nu[i].xuhao=i; $ }Panax NotoginsengSort (nu+1, nu+n+1, CMP); - Long Longsum=0; the for(inti=n;i>=1; i--){ +sum+=Summ (Nu[i].xuhao); A haha (n,nu[i].xuhao); the } +printf"%lld\n", sum); -memset (s),0,sizeof(s)); $ } $ return 0; -}
POJ 2299 Ultra-quicksort Reverse order to the template problem