题意:给一个数列,每次可以在后面加一个数,或者询问最后L个数中最大值,初始序列为空,强制在线,操作数<=200000
单调队列
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
typedef long long ll;
typedef unsigned long long ull;
ll F;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define MAXN (200001+10)
pair<ll,ll> p[MAXN];
int len=0;
int main()
{
// freopen("bzoj1012.in","r",stdin);
// freopen(".out","w",stdout);
int m=read();
F=read();
char c[2];
ll t,i=0,fans=0;
while(m--) {
scanf("%s%lld",c,&t);
if (c[0]=='A') {
p[++len]=mp(++i,(t+fans)%F);
if (len<2) continue;
while(len>=2&&p[len].se>=p[len-1].se) p[len-1]=p[len],len--;
}
else {
fans=lower_bound(p+1,p+1+len,mp(i-t+1,-1LL))->se;
printf("%lld\n",fans);
}
}
return 0;
}