最后两个点RE,前面全WA,就过了额外数据
#include <iostream>
#include <cstdio>
#include <cstring>
#define ll long long
const int N = 2e5 + 7;
using namespace std;
int n, cnt;
ll mod, t;
ll a[N], f[N][21], lg[N];
inline void update(int tot) {
f[tot][0] = a[tot];
for (int i = 1; tot - (1 << i) >= 0; ++ i)
f[tot][i] = std :: max(f[tot][i - 1], f[tot - (1 << (i - 1))][i - 1]);
}
int main() {
scanf("%d%lld", &n, &mod);
for (int i = 2; i <= n; ++ i)
lg[i] = lg[i >> 1] + 1;
for (int i = 1; i <= n; ++ i) {
char op[3];
ll x;
scanf("%s%lld", op + 1, &x);
if (op[1] == 'Q') {
int k = lg[cnt - x + 1];
t = (x == 1 ? a[cnt] : std :: max(f[cnt][k], f[cnt - x + (1 << k)][k]));
printf("%lld\n", t);
} else {
a[++ cnt] = (x + t) % mod;
update(cnt);
}
}
return 0;
}