Title: https://www.lydsy.com/JudgeOnline/problem.php?id=1012
Monotonous stack water problem. You can use Lower_bound.
But input do not char ch; Cin>>ch. Will tle. Why )
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;Const intn=2e5+5;intN,m,mod,stack[n],a[n],top,lst;intMain () {scanf ("%d%d",&m,&MoD); Charch[5];intx; while(m--) {scanf ("%s%d",ch,&x); if(ch[0]=='A') {(x+=LST)%=mod;a[++n]=x; while(Top&&x>=a[stack[top]]) top--; stack[++top]=N; } if(ch[0]=='Q') { intK=lower_bound (stack+1, stack+top+1, n-x+1)-Stack; LST=A[stack[k]]; printf ("%d\n", LST); } } return 0;}
Lower_bound
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;Const intn=2e5+5;intN,m,mod,stack[n],ps[n],top,lst;intMain () {scanf ("%d%d",&m,&MoD); Charch[5];intx; while(m--) {scanf ("%s%d",ch,&x); if(ch[0]=='A') {(x+=LST)%=MoD; while(Top&&x>=stack[top]) top--; stack[++top]=x;ps[top]=++N; } if(ch[0]=='Q') { intL=1, r=top; while(l<=r) {intMid= (l+r) >>1); if(ps[mid]>n-x) lst=mid,r=mid-1; ElseL=mid+1; } LST=Stack[lst]; printf ("%d\n", LST); } } return 0;}
Bzoj 1012 [JSOI2008] Maximum number MaxNumber