# Maximum number of "BZOJ1012" "JSOI2008" MaxNumber

Source: Internet
Author: User

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

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 (0

Output

For each query operation, you should output the results sequentially, with each result in one row.

Sample Input5 100
A 96
Q 1
A 97
Q 1
Q 2Sample Output96
93
theHINTmaintain a tree segment ... The insertion point and query are processed once. Source:
`#include <iostream>#include<cstdio>#defineN 200000using namespacestd;intsegtree[4*N];intN,me,ans;voidAddDataintNow ) {Segtree[now]=max (segtree[(now<<1)],segtree[(now<<1)+1]);}voidPointchange (intNowintLintRintXintv) {    if(L==R)    {segtree[now]+=v; Segtree[now]%=me;return;} intMid= (l+r) >>1; if(X<=mid) Pointchange (now<<1), l,mid,x,v); ElsePointchange ((now<<1)+1, mid+1, r,x,v); AddData (now);}voidQueryintNowintLintRintBeginintend) {    if(Begin<=l && end>=r) {Ans=max (Ans,segtree[now]);return;} intMid= (l+r) >>1; if(begin<=mid) query ((now<<1), l,mid,begin,end); if(end>mid) query ((now<<1)+1, mid+1, r,begin,end);}intMain () {inti,num=0, X; Chars[Ten]; scanf ("%d%d",&n,&me);  for(i=1; i<=n;i++) {scanf ("%s%d",s,&x); if(s[0]=='A') {num++; Pointchange (1,1, n,num,ans+x); }        Else{ans=-99999999; Query (1,1, n,num-x+1, num); printf ("%d\n", ans); }    }    return 0;}`

"BZOJ1012" "JSOI2008" Maximum number MaxNumber

Related Keywords:

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.