Blue Bridge Cup children in line

Source: Internet
Author: User

。。。 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.