"Monotone Stack" Bzoj 1012: Maximum number MaxNumber

Source: Internet
Author: User

1012: [JSOI2008] Maximum number of maxnumber time limit:3 Sec Memory limit:162 MB
submit:6255 solved:2676
[Submit] [Status] [Discuss] 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
the careless water had a monotonous stack over it. (Maintenance monotonic two points)CLJ Advanced Practices: http://wjmzbmr.com/archives/jsoi2008_maximum_number_maxnumber_of/    
1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <cmath>5 6 #defineMAXN 2000017 8typedefLong Longll;9 Ten using namespacestd; One  A structnode{ - ll C; -     intPos; the }STA[MAXN]; -  -ll top=0; -  +inline LLinch() - { +ll x=0;CharCh=GetChar (); A      while(ch<'0'|| Ch>'9') ch=GetChar (); at      while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); -     returnx; - } -  - voidAdd (ll num,intPOS) - { in      while(sta[top].c<=num&&top!=0) top--; -top++; tosta[top].c=num,sta[top].pos=Pos; + } -  thell Ask (intRintPOS) * { $     intL=1, an;Panax Notoginseng      while(l<=R) -     { the         intMid= (l+r) >>1; +         if(Sta[mid].pos>=pos) r=mid-1, an=mid; A         ElseL=mid+1; the     } +     returnsta[an].c; - } $  $ intMain () - { -     intn,nownum=0; thell d,num,lastans=0; -     Charsb;Wuyin=inch(), d=inch(); the      for(intI=1; i<=n;i++) -     { Wusb=0; -          while(sb!='A'&&sb!='Q') sb=GetChar (); Aboutnum=inch(); $         if*s = ='Q') printf ("%lld\n", Lastans=ask (top,nownum-num+1)); -         ElseAdd ((num%d+lastans%d)%d,++nownum); -     } -     return 0; A}
View Code

PS: Recent brain stump various small places wrong.

It's time for the exam to start writing the right shot.

PS: The preliminaries are 76. Think about it, if it weren't for HN but ZJ, it would have been a strange way to end the OI career. And the wrong kind of seemingly all Oi knowledge? (pointers, allowances, catanlan, etc.). I feel like I'm learning or not being too solid.

"Monotone Stack" Bzoj 1012: Maximum number MaxNumber

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.