Topic Portal
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 6 Const intMax_n =100000+Ten;7 intCnt[max_n];8 intAns[max_n];9 intMAXN =-1;Ten structnode One { A intS, E; - intID; - }cow[max_n]; the -InlineintReadvoid) - { - intx =0, F =1;CharCH =GetChar (); + while(Ch <'0'|| CH >'9') {if(ch = ='-') F =-1; CH =GetChar ();} - while(Ch >='0'&& CH <='9') {x = x *Ten+ CH-'0'; CH =GetChar ();} + returnX *F; A } at -InlinevoidPrintintx) - { - if(X <0) {Putchar ('-'); x =-x;} - if(X >9) Print (X/Ten); -Putchar (x%Ten+'0'); in } - to BOOLCMP (node x, node Y)//sort e from big to small first + { - if(X.E = =y.e) the returnX.s < Y.S;//if equal, then press S to sort from small to large * Else $ returnX.E >y.e;Panax Notoginseng } - the intLowbit (intT//Beg 2^t + { A //return T & (t ^ (t-1)); the returnT & (-t); + } - $ voidPlusintx) $ { - while(x <=MAXN) - { theans[x]++;//record the number of strong cows -X + =lowbit (x);Wuyi } the } - Wu intSumintX//Count the number of strong cows before X - { About intsum =0; $ while(X >0) - { -Sum + =Ans[x]; -X-=lowbit (x); A } + returnsum; the } - $ intMainvoid)//POJ 2481 Cows the { the //freopen ("InH.txt", "R", stdin); the intN; the - while(SCANF ("%d", &n) &&N) in { the for(intI=1; i<=n; ++i) the { AboutCOW[I].S = Read (); COW[I].E = Read ();//read the plug-in optimization the //scanf ("%d%d", &cow[i].s, &COW[I].E); theCow[i].id =i; theMAXN =Max (MAXN, COW[I].E); + } -memset (ans,0,sizeof(ans)); theSort (cow+1, cow+n+1, CMP);Bayi for(intI=1; i<=n; ++i) the { the if(COW[I].E = = cow[i-1].E && Cow[i].s = = cow[i-1].S)//if the values are equal, do not add statistics -Cnt[cow[i].id] = cnt[cow[i-1].id]; - Else the { theCnt[cow[i].id] = SUM (Cow[i].s +1);//ID of the cow how much stronger than it the } thePlus (Cow[i].s +1); - } the intJ; the for(j=1; j<n; ++j) the {94Print (Cnt[j]); Putchar (' ');//output plug -in optimization the //printf ("%d", cnt[j]); the } theprintf ("%d\n", Cnt[j]);98 } About - return 0;101}
Tree-like array POJ 2481 cows