求大佬帮改
P1198
#include<bits/stdc++.h>
using namespace std;
int n,d,t,x,a[200005],b[200005],sz,cnt;
char op;
int main() {
cin>>n>>d;
for(int i=1; i<=n; i++)
{
cin>>op>>x;
if(op=='A') {
a[++cnt]=(x+t)%d;
while(sz&&a[cnt]) sz--;
b[sz++]=cnt;
} else if(op=='Q') {
int p=lower_bound(b,b+sz,cnt-x+1)-b;
t=a[b[p]];
cout<<t<<endl;
}
}
}