蒟蒻只能AC单调栈的做法了
#include<cstdio> #include<cctype> #include<algorithm> using namespace std; int a[200004],num[200004]; inline int read(){ char ch=getchar();int k=0; while(!isdigit(ch)) ch=getchar(); while(isdigit(ch)){k=(k<<1)+(k<<3)+ch-‘0‘;ch=getchar();} return k; } int main(){ int n=read(),cnt=0,top=0,mod=read(),t=0; while(n--){ char c;scanf(" %c",&c);int x=read(); if(c==‘A‘){ x=(x+t)%mod; num[++cnt]=x; while(top&&num[a[top]]<=x)top--; a[++top]=cnt; } else{ int y=lower_bound(a+1,a+top+1,cnt-x+1)-a; t=num[a[y]]; printf("%d\n",t); } } return 0; }