Two times Unicom Gate: Luogu P1198 [JSOI2008] Maximum number
/*Luogu P1198 [JSOI2008] Maximum number of segments tree water over ... Built an empty tree and then single-point insertion, interval query can be*/#include<cstdio>#defineMax 200000voidRead (Long Long&Now ) { Now=0; RegisterCharWord =GetChar (); while(Word >'9'|| Word <'0') Word=GetChar (); while(Word >='0'&& Word <='9') { now= Now *Ten+ Word-'0'; Word=GetChar (); }} inlineLong LongMax (Long LongALong Longb) { returna > B?a:b;}Long LongN;Long LongMod;structsegment{structSegment_tree {Long Longl; Long LongR; Long LongMid; Long LongMAXN; }; Segment_tree Tree[max<<3]; voidTree_build (Long LongLLong LongRLong LongNow ) {TREE[NOW].L=l; TREE[NOW].R=R; if(L = =R)return ; Tree[now]. Mid= (L + r) >>1; Tree_build (L, Tree[now]. Mid, now<<1); Tree_build (Tree[now]. Mid+1, R, now <<1|1); } voidTree_insert (Long LongPosLong LongNowLong LongNumber ) { if(TREE[NOW].L = =TREE[NOW].R) {Tree[now]. MAXN=Number ; return ; } if(Pos <=Tree[now]. Mid) Tree_insert (POS, now<<1, number); ElseTree_insert (POS, now<<1|1, number); Tree[now]. MAXN= Max (Tree[now <<1]. MAXN, Tree[now <<1|1]. MAXN); } Long LongTree_query (Long LongLLong LongRLong LongNow ) { if(TREE[NOW].L = = L && TREE[NOW].R = =R)returnTree[now]. MAXN; if(R <=Tree[now]. Mid)returnTree_query (L, R, now <<1); Else if(L >Tree[now]. Mid)returnTree_query (L, R, now <<1|1); Else returnMax (Tree_query (L, Tree[now). Mid, now <<1), Tree_query (Tree[now]. Mid +1, R, now <<1|1)); } }; Segment Tree;Long LongTree_pos;intMain (intargcChar*argv[]) {Read (N); Read (MOD); Tree_pos=0; Tree.tree_build (1N1); Chartype[5]; Long Longx; Long Longt =0; while(n--) {scanf ("%s", type); Read (x); if(type[0] =='Q') {T= Tree.tree_query (Tree_pos-x +1, Tree_pos,1); printf ("%lld\n", T); } ElseTree.tree_insert (++tree_pos,1, (x + t)%Mod); } return 0;}
Luogu P1198 [JSOI2008] Maximum number