Topic Links:
1012: [JSOI2008] Maximum number of maxnumber Time Limit:3 Sec Memory limit:162 MB
Description
Now ask you to maintain a sequence, the following two operations are required: 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
On 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 taken to 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
the
Test Instructions :
ideas :entry question for line segment tree;
AC code :
#include <bits/stdc++.h>using namespacestd;#defineRiep (n) for (int i=1;i<=n;i++)#defineRIOP (n) for (int i=0;i<n;i++)#defineRJEP (n) for (int j=1;j<=n;j++)#defineRJOP (n) for (int j=0;j<n;j++)#defineMST (SS,B) memset (ss,b,sizeof (b));typedefLong LongLL;ConstLL mod=1e9+7;Const DoublePi=acos (-1.0);Const intinf=0x3f3f3f3f;Const intn=2e5+6;intm; LL D;structnode{intL,r; LL num;} tree[4*N];voidPushup (intnode) {Tree[node].num=max (tree[2*node].num,tree[2*node+1].num);}voidBuildintNodeintLintR) {TREE[NODE].L=L; TREE[NODE].R=R; Tree[node].num=0; if(L==R)return ; intMid= (l+r) >>1; Build (2*node,l,mid); Build (2*node+1, mid+1, R); Pushup (node);}voidUpdateintNodeintpos,ll num) { if(tree[node].l==tree[node].r&&tree[node].l==POS) {Tree[node].num=num; return ; } intMid= (TREE[NODE].L+TREE[NODE].R) >>1; if(pos<=mid) Update (2*node,pos,num); ElseUpdate2*node+1, Pos,num); Pushup (node);} LL Query (intNodeintLintR) { if(l<=tree[node].l&&r>=TREE[NODE].R) { returnTree[node].num; } intMid= (TREE[NODE].L+TREE[NODE].R) >>1; if(R<=mid)returnQuery2*node,l,r); Else if(L>mid)returnQuery2*node+1, L,r); Else returnMax (Query (2*NODE,L,MID), Query (2*node+1, mid+1, R));}intMain () { while(SCANF ("%d%lld", &m,&d)! =EOF) { intCnt=1; LL T=0; Build (1,1, M); Riep (m) {Chars; scanf ("%c",&s); if(s=='A') {LL n; scanf ("%lld",&N); N+=T; N%=D; Update (1, Cnt,n); CNT++; } Else { intLen; scanf ("%d",&Len); //cout<<cnt-len<< "" <<cnt-1<< "@" <<endl;T=query (1, cnt-len,cnt-1); printf ("%lld\n", T); } } } return 0;}
bzoj-1012 1012: [JSOI2008] Maximum number of maxnumber (segment tree)