You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
typedef long long LL;
|
|
|
|
|
using namespace std;
|
|
|
|
|
const int N = 2e5 + 10;
|
|
|
|
|
int m, p;
|
|
|
|
|
|
|
|
|
|
LL c[N];
|
|
|
|
|
typedef long long LL;
|
|
|
|
|
#define lowbit(x) (x & -x)
|
|
|
|
|
void add(int x, LL d) {
|
|
|
|
|
for (int i = x; i < N; i += lowbit(i)) c[i] = max(c[i], d);
|
|
|
|
|
}
|
|
|
|
|
LL query(int x) {
|
|
|
|
|
LL res = 0;
|
|
|
|
|
for (int i = x; i; i -= lowbit(i)) res = max(res, c[i]);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
// 加快读入
|
|
|
|
|
ios::sync_with_stdio(false), cin.tie(0);
|
|
|
|
|
cin >> m >> p; // m次操作,p是模值
|
|
|
|
|
int last = 0; // last 是在这个添加操作之前最后一个询问操作的答案(如果之前没有询问操作,则 a=0)。
|
|
|
|
|
int j = m;
|
|
|
|
|
// j的物理含义:
|
|
|
|
|
// 倒数第1个,放到第m个位置
|
|
|
|
|
// 倒数第2个,放到第m-1个位置
|
|
|
|
|
// ...
|
|
|
|
|
// 倒数第m个,放到第1个位置
|
|
|
|
|
for (int i = 0; i < m; i++) {
|
|
|
|
|
char c;
|
|
|
|
|
cin >> c;
|
|
|
|
|
if (c == 'A') { // 表示向序列后面加一个数
|
|
|
|
|
LL t;
|
|
|
|
|
cin >> t; // t:是输入的参数
|
|
|
|
|
// j--:倒着存入
|
|
|
|
|
add(j--, (t + last) % p);
|
|
|
|
|
} else { // 表示这个操作是询问序列中最后 L 个数的最大数是多少
|
|
|
|
|
LL L;
|
|
|
|
|
cin >> L;
|
|
|
|
|
last = query(j + L); // 下次需要本次的结果
|
|
|
|
|
printf("%d\n", last);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|