这个?乱入线段树。我写的还特别暴力结果还是过了。。。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define maxn 1000050
using namespace std;
long long ls[maxn],rs[maxn],value[maxn];
long long m,d,last=0,n,rec=0,tot=0,root=0;
char type[5];
long long build(long long left,long long right)
{
long long now=++tot;
if (left==right)
return now;
long long mid=(left+right)>>1;
ls[now]=build(left,mid);
rs[now]=build(mid+1,right);
return now;
}
void single_modify(long long now,long long left,long long right,long long pos,long long x)
{
if ((left==pos) && (left==right))
{
value[now]=x;
return;
}
long long mid=(left+right)>>1;
if (pos<=mid) single_modify(ls[now],left,mid,pos,x);
else single_modify(rs[now],mid+1,right,pos,x);
value[now]=max(value[ls[now]],value[rs[now]]);
}
long long ask(long long now,long long left,long long right,long long l,long long r)
{
if ((left==l) && (right==r))
return value[now];
long long mid=(left+right)>>1;
if (r<=mid) return ask(ls[now],left,mid,l,r);
else if (l>=mid+1) return ask(rs[now],mid+1,right,l,r);
else return max(ask(ls[now],left,mid,l,mid),ask(rs[now],mid+1,right,mid+1,r));
}
int main()
{
scanf("%lld%lld",&m,&d);
root=build(1,m);
for (long long i=1;i<=m;i++)
{
scanf("%s %d",type,&n);
if (type[0]=='Q')
{
last=ask(root,1,m,rec-n+1,rec);
printf("%lld
",last);
}
else
{
n=(n+last)%d;rec++;
single_modify(root,1,m,rec,n);
}
}
return 0;
}