如题。头要挠秃了。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll st[N][20];
int M,n;
ll D;
ll query(int L){
int k=log2(L);
int l=n-L+1;
return max(st[l][k],st[n-(1<<k)+1][k]);
}
void upd(ll x){
st[++n][0]=x;
for(int j=1;(1<<j)<=n;j++){
int L=n-(1<<j)+1;
st[L][j]=max(st[L][j-1],st[L+(1<<(j-1))][j-1]);
}
}
int main(){
char c;
ll x,t;
cin>>M>>D;
for(int i=1;i<=M;i++){
cin>>c>>x;
if(c=='A'){
upd(((x+t)%D+D)%D);
}else{
t=query(x);
cout<<t<<endl;
}
}
return 0;
}