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