洛谷p1198 最大数
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; int m,d,head,tail,pos; char op[2]; typedef long long ll; int q[200007],a[200007]; int main(){ while(~scanf("%d%d",&m,&d)){ int t=0,x;head=tail=0; while(m--){ scanf("%s%d",op,&x); if(op[0]=='A'){ x=(x+t)%d; a[pos++]=x; if(tail==0){ q[tail++]=pos-1; } else{ while(tail&&a[q[tail-1]]<=x) tail--;//err q[tail++]=pos-1; } } else{ int index=lower_bound(q,q+tail,pos-x+1-1)-q; t=a[q[index]];//err printf("%d\n",a[q[index]]); } } } return 0; }