。。。 The beginning of a silly violence.
Later only to know is the tree-like array in reverse order number.
Look at the amount of data first!
#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<string>#include<queue>#include<algorithm>#include<map>#include<iomanip>#include<climits>#include<string.h>#include<cmath>#include<stdlib.h>#include<vector>#include<stack>#include<Set>using namespacestd;#defineINF 1000000007#defineMAXN 4010#defineMod 1000007#defineN 100010#defineNN 30#defineSigma_size 3Const intMAX =1000100;Const intMAXN = 6e5 +Ten;using namespaceStd;typedefLong LongLL; LL Total[n], ans;intNum[n], C[max], S[max], b[n];intLowbit (intx) { returnx& (-x);}voidAddintPosintNumint*p) { while(Pos <=MAX) {P[pos]+=num; POS+=Lowbit (POS); }}intSumintEndint*Q) { intCNT =0; while(End >0) {CNT+=P[end]; End-=lowbit (end); } returnCNT;}voidinit () {total[0] =0; for(inti =1; i < N; ++i) {Total[i]= Total[i-1] +i; }}intMain () {intT; Init (); while(Cin >>t) { for(intj =0; J < T; ++J) {//since the first number is less than the number in front of it, J should start from 0CIN >>Num[j]; Add (Num[j]+1,1, C); B[J]= J-sum (Num[j], C);;//Sum (num[j],c) is the number of less than num[j], j-sum (NUM[J],C) is the number of the number of previous j is greater than Num[j]B[J]-= SUM (Num[j] +1, c)-sum (Num[j], c)-1;//does not include the number itself} ans=0; for(intj = T-1; J >-1; --J) {//In turn, the number of digits to the right of the first J numberAdd (Num[j] +1,1, S); B[J]+ = SUM (Num[j], S);//sum (num[j],s) is the number of less than num[j]Ans + =Total[b[j]]; } cout<< ans <<Endl; } return 0;}
Blue Bridge Cup children in line