Bare Segment Tree ... Because the array is small and always re. Wasted a lot of time.
--------------------------------------------------------------------------
#include <cstdio> #include <algorithm> #include <cstring> #include <cctype> #include < Iostream> #define REP (i,n) for (int i=0;i<n;i++) #define CLR (x,c) memset (x,c,sizeof (x)) using namespace Std; const int Maxnode=800005;const int INF=0X7FFFFFFF; int mod; struct Segmenttree {int ql,qr,v,p,n;int Maxv[maxnode];void init (int n) {this->n=n;}int QUERY (int o,int l,int r) {if (ql<=l && qr>=r) return maxv[o];int mid=l+ (r-l)/2,ans=-inf;if (ql<=mid) Ans=max (Ans,query (O*2,l,mid));if (qr>mid) Ans=max (Ans,query (o*2+1,mid+1,r));return ans;}void UPDATE (int o,int l,int r) {int mid=l+ (R-L)/2;if (l==r) maxv[o]=v;else {if (p<=mid) UPDATE (O*2,l,mid);else UPDATE (O*2+1,MID+1,R);Maxv[o]=max (maxv[o*2],maxv[o*2+1]);}}int query (int l,int r) {Ql=l; Qr=r;Return QUERY (1,1,n);}void Update (int i,int val) {V=val; P=i;UPDATE (1,1,n);}} St;int main () {//Freopen ("Test.in", "R", stdin);//Freopen ("Test.out", "w", stdout);int n,ans=0,cnt=0,num;scanf ("%d%d", &n,&mod);char c;St.init (n);while (n--) {while (scanf ("%c", &c) &&!isupper (c));scanf ("%d", &num);if (c== ' Q ') printf ("%d\n", Ans=st.query (cnt-num+1,cnt));else St.update (++cnt, (Num+ans)%mod);}return 0;}
--------------------------------------------------------------------------
1012: [JSOI2008] Maximum number maxnumber time limit: 3 Sec Memory Limit: 162 MB
Submit: 4787 Solved: 2162
[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
Bzoj 1012: [JSOI2008] Maximum number of maxnumber (segment tree)