-
Notifications
You must be signed in to change notification settings - Fork 0
/
P1198_ST.cpp
43 lines (43 loc) · 970 Bytes
/
P1198_ST.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
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#define INF 0x3f3f3f3f
const long long MOD = pow(10,9) + 7;
using namespace std;
long long st[200000][20];
long long a[200000];
int M, cnt = 0;
long long D;
void update(int val) {
int j = 0;
while ( 1 + cnt >= (1<<j)) {
if (j == 0)
st[1 + cnt - (1<<j)][j] = val;
else
st[1 + cnt - (1<<j)][j] = max(st[1+cnt-(1<<(j-1))][j-1],st[1 + cnt - (1<<j)][j-1]);
j++;
}
cnt++;
}
int main() {
scanf("%d %lld", &M, &D);
char c;
long long n;
long long ret = 0;
for (int i = 0; i < M; ++i) {
scanf(" %c %lld", &c, &n);
if (c == 'A') {
n = (ret + n) % D;
update(n);
}
else {
int j = log(n) / log(2);
ret = max(st[cnt - (1<<j)][j],st[cnt - n][j]);
printf("%lld\n",ret);
}
}
}