Luogu P1198 [JSOI2008] Maximum number

Source: Internet
Author: User

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

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.