Time Limit:3 Sec Memory limit:162 MB
submit:13258 solved:5737
[Submit] [Status] [Discuss] Description
Now you are asked to maintain a sequence that requires the following two actions:
1, query operation.
syntax: Q L function: Query the end of the current sequence of L The largest number in the number, and outputs the value of the 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 a fixed constant d 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 there is no number.
Input
The first line is two integers, M and D, where m represents the number of operations (M <= 200,000), D, as described above, satisfies D within Longint. Next
M row, query operation, or insert operation.
Output
For each query operation, output a line. The line has only one number, which is the maximum number of the last L in the sequence.
Sample Input5 100
A 96
Q 1
A 97
Q 1
Q 2Sample Output96
93
theHINT
The data is as follows Http://pan.baidu.com/s/1i4JxCH3
Source
Classic line Segment Tree
It turns out that Bzoj never use cin/cout.
It turns out that Bzoj never use cin/cout.
It turns out that Bzoj never use cin/cout.
Tuned me for one hours!!!
1#include <iostream>2#include <cstdio>3 using namespacestd;4 5 Const intmaxn=800010;6 7 intTREE[MAXN];8 intM,d,t,pos;9 Ten voidUpdateintKintLintRintx) One { A if(L==R) {tree[k]=x;return;} - intMid= (l+r) >>1; - if(pos<=mid) Update (k<<1, l,mid,x); the ElseUpdate (k<<1|1, mid+1, r,x); -Tree[k]=max (tree[k<<1],tree[k<<1|1]); - } - + intSearchintKintLintRintSintt) - { + if(l==s&&r==t)returnTree[k]; A intMid= (l+r) >>1; at if(T<=mid)returnSearch (k<<1, l,mid,s,t); - if(S>mid)returnSearch (k<<1|1, mid+1, r,s,t); - returnMax (Search (k<<1, L,mid,s,mid), search (k<<1|1, mid+1, r,mid+1, T)); - } - - intMain () in { -scanf"%d%d",&m,&D); to for(intI=1; i<=m;i++) + { - Charo[5];intN; thescanf"%s", O); *scanf"%d",&n); $ if(o[0]=='A')Panax Notoginseng { -pos++; theUpdate1,1, M, (n+t)%D); + } A Else the { +T=search (1,1, m,pos-n+1, POS); -printf"%d\n", T); $ } $ } - return 0; -}
1012: [JSOI2008] Maximum number of maxnumber