RT,不知道为什么MLE,样例已过
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll MAXN=2e5+5;
ll n,m,mod,record,maxs[MAXN<<2],topcnt,add_num;
char op;
ll lson(ll x){return x<<1;}
ll rson(ll x){return x<<1|1;}
void push_up(ll x){
maxs[x]=max(maxs[lson(x)],maxs[rson(x)]);
}
void add(ll now,ll l,ll r,ll x,ll k){
if(l==r){
maxs[now]=k;
return;
}
ll mid=(l+r)>>1;
if(x<=mid)add(lson(now),l,mid,x,k);
else add(rson(now),mid+1,r,x,k);
push_up(now);
}
ll query(ll now,ll l,ll r,ll ql,ll qr){
if(ql<=l&&r<=qr)return maxs[now];
ll mid=(l+r)>>1,query_max=0;
if(ql<=mid)query_max=max(query_max,query(lson(now),l,mid,ql,qr));
if(mid<qr)query_max=max(query_max,query(rson(now),mid+1,r,ql,qr));
return query_max;
}
signed main()
{
IOS;
cin>>m>>mod;
while(m--){
cin>>op>>n;
switch(op){
case 'A':{
++topcnt;
add_num=(n+record)%mod;
add(1,1,m,topcnt,add_num);
break;
}
case 'Q':{
cout<<(record=query(1,1,m,topcnt-n+1,topcnt))<<"\n";
break;
}
}
}
return 0;
}