Files
python/TangDou/AcWing/SegmentTree/1275_SZSZ.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

46 lines
1.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}