BZOJ传送门
水题一道,线段树维护即可。(省选题出模板?)
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#define ms(i,j) memset(i,j, sizeof i);
using namespace std;
const int MAXM = 200000+5;
int m,d;
#define lc (o<<1)
#define rc (o<<1|1)
#define M ((l+r)>>1)
struct st
{
int maxv[MAXM*4];
void pushup(int o)
{
maxv[o] = max(maxv[lc], maxv[rc]);
}
void build(int o, int l, int r)
{
maxv[o] = 0;
if (l==r) return ;
build(lc, l, M);
build(rc, M+1,r);
}
void update(int o, int l, int r, int p, int v)
{
if (l==r)
{
maxv[o] += v;
return ;
}
if (p<=M) update(lc, l, M, p, v);
else if (M<p) update(rc, M+1, r, p, v);
pushup(o);
}
int query(int o, int l, int r, int x, int y)
{
if (x<=l&&r<=y)
{
return maxv[o];
}
int ans = -1;
if (x<=M) ans = max(query(lc, l, M, x, y), ans);
if (M<y) ans = max(query(rc, M+1, r, x, y), ans);
return ans;
}
}tree;
int getc()
{
char ans;
while (true)
{
ans = getchar();
if (ans=='A') return 0;
else if (ans=='Q') return 1;
}
}
int main()
{
scanf("%d%d", &m, &d);
tree.build(1,1,m);
int last = 0;
int cnt = 0;
for (int i=1;i<=m;i++)
{
int opt = getc();
int x;
scanf("%d", &x);
if (opt==0)
{
cnt++;
x = (x+last)%d;
tree.update(1,1,m,cnt, x);
} else
{
printf("%d\n", last = tree.query(1,1,m,cnt-x+1,cnt));
}
}
return 0;
}