HDU 5372 Segment Game "tree-shaped Array"

Source: Internet
Author: User

Give some action,

0 is to place the segment I added in the B position, the length of the segment I put is I

1 is the removal of the segment of the B-increment operation

After each increment, ask the number of the complete line segment above this line segment

Each query counts the number of lines of a segment that is larger than the left end of the segment L, the number of lines of the segment that is larger than the right end of the segment R, and two subtraction is the number of lines of the complete segment

Also because the given B is very large, so it needs to be discretized, and B may be the same, so the same size should occupy a number

And then it's like asking for a reverse order.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <stack>6#include <vector>7#include <map>8#include <Set>9#include <queue>Ten#include <algorithm> One using namespacestd; A  -typedefLong LongLL; - Const intINF = (1<< -)-1; the Const intMod=1000000007; - Const intmaxn=500005; -  - intN; + intA[MAXN],C[MAXN],B[MAXN]; -  + intLowbit (intx) {returnX & (-x);} A  at intSUM1 (intx) { -     intRET =0; -      while(x>0){ -ret+=c[x];x-=lowbit (x); -     } -     returnret; in } -  to voidADD1 (intXintd) { +      while(x<=MAXN) { -c[x]+=d;x+=lowbit (x); the     } * } $ Panax Notoginseng intSUM2 (intx) { -     intRET =0; the      while(x>0){ +ret+=b[x];x-=lowbit (x); A     } the     returnret; + } -  $ voidADD2 (intXintd) { $      while(x<=MAXN) { -b[x]+=d;x+=lowbit (x); -     } the } - Wuyi structnode{ the     intx, y; -     intL,r; Wu     intLb,ub; -     intID; About     intidx; $ }; -  - intCMP1 (node N1,node n2) { -     returnN1.L <N2.L; A } +  the intCMP2 (node N1,node n2) { -     returnN1.R <N2.R; $ } the  the node P[MAXN],CMD[MAXN],ADD[MAXN]; the  the intMain () { -     intQ; in     intKase =0; the      while(SCANF ("%d", &q)! =EOF) { theMemset (A,0,sizeof(a)); Aboutmemset (b,0,sizeof(b)); theMemset (c,0,sizeof(c)); the          the         intCNT =1; +          for(inti =1; I <= q;i++){ -scanf"%d%d",&cmd[i].x,&cmd[i].y); the             if(cmd[i].x = =0){BayiCmd[i].id =CNT; theADD[CNT].L = CMD[I].Y; P[CNT].L =cmd[i].y; theADD[CNT].R = add[cnt].l + CNT;P[CNT].R = add[cnt].l +CNT; -Add[cnt].idx = Cnt;p[cnt].idx =CNT; -cnt++; the             } the         } theprintf"Case #%d:\n",++Kase); the          -Sort (p+1, p+cnt,cmp1); the          for(intI=1, j=0;i< cnt;i++){ the              if(i==1|| P[i].l! = p[i-1].L) J + +; theadd[p[i].idx].lb=J;94          } the          theSort (p+1, p+cnt,cmp2); the          for(intI=1, j=0;i< cnt;i++){98              if(i==1|| P[I].R! = p[i-1].R) J + +; Aboutadd[p[i].idx].ub=J; -          }101         102         103          for(inti =1; I <= q;i++){104             if(cmd[i].x = =0){ the                 intK =cmd[i].id;106                 intC1 =add[k].lb;107                 intC2 =Add[k].ub;108                 intL = (K-1)-SUM1 (C1-1);109                 intr = (K-1)-sum2 (C2); the                 intAns = ABS (lR);111printf"%d\n", ans); theADD1 (C1,1); Add2 (C2,1);113             } the             if(cmd[i].x = =1){ the                 intK =cmd[i].y; the                 intC1 =add[k].lb;117                 intC2 =Add[k].ub;118                 intD1 = SUM1 (C1)-Sum1 (c1-1);119                 if(D1! =0) Add1 (c1,-1); -                 121                 intD2 = sum2 (C2)-Sum2 (c2-1);122                 if(D2! =0) Add2 (c2,-1);123             }124         } the     }126     return 0;127}
View Code

HDU 5372 Segment Game "tree-shaped Array"

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.