"Title description"
Now ask you to maintain a sequence, the following two operations are required: 1, query operation. Syntax: Q L function: Query the maximum number of L in the number of the end of the current sequence and output the value of this number. Limit: l does not exceed the length of the current series. 2, insert operation. Syntax: a n function: N plus t, where T is the answer to the most recent query operation (t=0 if the query operation has not been performed), and the resulting result is modeled on a fixed constant d and the resulting answer is inserted at the end of the sequence. Limit: N is a non-negative integer and is within a long range. Note: The initial sequence is empty and does not have a number.
"Input Format"
The first line is two integers, M and D, where m represents the number of operations (M <= 200,000) and D, as described above, satisfies 1≤intMA x
"Output Format"
For each query operation, you should output the results sequentially, with each result in one row.
"Sample Input"
5 100A 96Q 1 a 97Q 1Q 2
"Sample Output"
969396
/*segment Tree Maintenance maximum Note that n here can be the number of queries, because n is the maximum number of queries*/#include<cstdio>#include<iostream>#defineM 200010#defineLson l,m,now*2#defineRson m+1,r,now*2+1#defineLL Long Longusing namespacestd; LL mx[m*4],mod,t=0, N; LL Read () {CharC=getchar (); LL num=0, flag=1; while(c<'0'|| C>'9'){if(c=='-') flag=-1; c=GetChar ();} while(c>='0'&&c<='9') {num=num*Ten+c-'0'; c=GetChar ();} returnnum*Flag;}voidPUSH_UP (intNow ) {Mx[now]=max (mx[now*2],mx[now*2+1]);}voidInsert (LL v,ll pos,ll l,ll r,ll now) {if(l==R) {Mx[now]=v; return; } LL M= (l+r)/2; if(pos<=m) insert (V,pos,lson); ElseInsert (V,pos,rson); PUSH_UP (now);} ll query (ll x,ll y,ll l,ll r,ll now) {if(l>=x&&r<=y)returnMx[now]; LL m= (l+r)/2; LL ans=0; if(m>=x) ans=Max (Ans,query (X,y,lson)); if(m<y) ans=Max (Ans,query (X,y,rson)); returnans;}intMain () {Freopen ("bzoj_1012.in","R", stdin); Freopen ("Bzoj_1012.out","W", stdout); LL T=read (), p=0; Mod=read (); n=u; while(t--) { CharC;cin>>C; LL x=read (); if(c=='Q') {LL ans=query (p-x+1P1N1); cout<<ans<<Endl; T=ans; } Else{p++; Insert ((x+T)%mod,p,1N1); } } return 0;}
View Code
Maximum number (COGS 1844)