-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP1198 [JSOI2008]最大数.cpp
78 lines (70 loc) · 1.48 KB
/
P1198 [JSOI2008]最大数.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
const int maxn = 200000 << 2;
LL tr[maxn];
void add(int now, int l, int r, int u, LL v) {
if(l==r) {
if(l==u) tr[now] = v;
return;
}
int mid = (l+r)>>1;
int lchild = now<<1;
int rchild = (now<<1)+1;
if(u>mid) {
add(rchild, mid+1, r, u, v);
}
else {
add(lchild, l, mid, u, v);
}
tr[now] = max(tr[lchild], tr[rchild]);
}
LL query(int now, int l, int r, int start, int end) {
if(l>=start && r<=end) return tr[now];
int mid = (l+r)>>1;
int lchild = now<<1;
int rchild = (now<<1) + 1;
if(start>mid) {
return query(rchild, mid+1, r, start, end);
}
else {
if(end>mid) {
return max(query(lchild, l, mid, start, end), query(rchild, mid+1, r, start, end));
}
else {
return query(lchild, l, mid, start, end);
}
}
}
int m;
LL d;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// add(1, 1, 1e5, 1, 96);
// add(1, 1, 1e5, 2, 93);
// cin >> m >> d;
// tr[1] = Node(1, maxn-1, 0);
// cout << query(1, 1, 1e5, 2, 2) <<endl;
// cout << query(1, 1, 1e5, 1, 2) <<endl;
cin >> m >> d;
char option; int n;register int len = 1;LL t = 0;
for(int i=0; i<m; i++) {
cin >> option >> n;
switch(option) {
case 'Q': {
t = query(1, 1, m, len-n, len);
cout << t << endl;
break;
}
case 'A': {
add(1, 1, m, len++, (n+t)%d);
break;
}
default: {
break;
}
}
}
return 0;
}