1 /**************************************************************
2 Problem: 1012
3 User: AsmDef
4 Language: C++
5 Result: Accepted
6 Time:364 ms
7 Memory:2836 kb
8 ****************************************************************/
9
10 //Asm_Def
11 #include <iostream>
12 #include <cctype>
13 #include <cstdio>
14 #include <vector>
15 #include <algorithm>
16 #include <cmath>
17 #include <queue>
18 using namespace std;
19 template<typename T>inline void getd(T &x){
20 char c = getchar();
21 bool minus = 0;
22 while(!isdigit(c) && c != ‘-‘)c = getchar();
23 if(c == ‘-‘)minus = 1, c = getchar();
24 x = c - ‘0‘;
25 while(isdigit(c = getchar()))x = x * 10 + c - ‘0‘;
26 if(minus)x = -x;
27 }
28 /*======================================================*/
29 const int maxn = 200002;
30 typedef long long LL;
31 inline int lowbit(int x){return x & -x;}
32 struct Fenwick{
33 LL A[maxn];
34 int iter;
35 Fenwick():iter(maxn - 1){}
36 inline void insert(LL x){
37 A[iter] = x;
38 int i = iter + lowbit(iter);--iter;
39 while(i < maxn){
40 if(x > A[i])A[i] = x;
41 i += lowbit(i);
42 }
43 }
44 inline int getmax(int L){
45 int i = iter + L, ans = 0;
46 while(i >= iter){
47 if(ans < A[i])ans = A[i];
48 i ^= lowbit(i);
49 }
50 return ans;
51 }
52 }BIT;
53 int main(){
54 #if defined DEBUG
55 freopen("test", "r", stdin);
56 #else
57 //freopen("bzoj_1012.in", "r", stdin);
58 //freopen("bzoj_1012.out", "w", stdout);
59 #endif
60 LL D, x, t = 0;
61 int M, opt;
62 getd(M), getd(D);
63 while(M--){
64 while(!isalpha(opt = getchar()));
65 getd(x);
66 if(opt == ‘Q‘)
67 printf("%d\n", t = BIT.getmax(x));
68 else BIT.insert((t + x) % D);
69 }
70
71
72 #if defined DEBUG
73 cout << endl << (double)clock()/CLOCKS_PER_SEC << endl;
74 #endif
75 return 0;
76 }