比赛 |
线段数树状数组 |
评测结果 |
AAAAAAAAAA |
题目名称 |
最大数 |
最终得分 |
100 |
用户昵称 |
jekyll |
运行时间 |
2.412 s |
代码语言 |
C++ |
内存使用 |
9.47 MiB |
提交时间 |
2018-06-18 19:58:00 |
显示代码纯文本
#include<cstdio>
#include<iostream>
#define lc rt<<1
#define rc rt<<1|1
#define st 1, n, 1
#define ls l, mid, rt<<1
#define rs mid + 1, r, rt<<1|1
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int maxN = 200005;
ll tree[maxN * 4], a[maxN], maxtag[maxN];
ll n, m, d, t;
void maxupdate(ll P, ll l, ll r, ll rt, ll num)
{
tree[rt] = max(num, tree[rt]);
ll mid = (l + r) >> 1;
if (l == r) return;
if (P <= mid) maxupdate(P, ls, num);
if (mid < P) maxupdate(P, rs, num);
}
ll query(ll L, ll R, ll l, ll r, ll rt)
{
if (L <= l && r <= R) return tree[rt];
ll ans = 0, mid = (l + r) >> 1;
if (L <= mid) ans = max(ans, query(L, R, ls));
if (mid < R) ans = max(ans, query(L, R, rs));
return ans;
}
inline ll readll()
{
ll X = 0, w = 0; char ch = 0;
while (ch > '9' || ch < '0') w = w | ch == '-', ch = getchar();
while (ch <= '9' && ch >= '0') X = (X<<3) + (X<<1) + (ch^48), ch = getchar();
return w ? -X: X;
}
int main()
{
freopen("bzoj_1012.in", "r", stdin);
freopen("bzoj_1012.out", "w", stdout);
n = readll(), d = readll();
for (int i = 1; i <= n; ++i)
{
char ch; cin >> ch;
if (ch == 'A')
{
ll k = readll(); k = (k + t) % d;
maxupdate(++m, st, k);
}
else
{
ll k = readll();
printf("%lld\n", t = query(m - k + 1, m, st));
}
}
return 0;
}