bzoj1012[最大数]

来源:互联网 发布:淘宝怎么养号养到钻号 编辑:程序博客网 时间:2024/06/13 11:48

http://www.lydsy.com/JudgeOnline/problem.php?id=1012

我是蒟蒻!~~~~~~~~~~~~~~~~~~


不知道什么为毛可以搞成单调栈- - -


蒟蒻的我直接写了线段树,维护一个当前序列长度cnt,然后每次查询(cnt-n+1,cnt)的最大值

加入一个cnt++


#include<cstdio>#include<iostream>#include<cstring>#include<cstdlib>#include<algorithm>#include<queue>#include<cmath>#define LL long longusing namespace std;const LL maxn=200000+20;struct node{LL l,r,mm;}T[maxn<<2];LL m,M;void pushup(LL i){T[i].mm=max(T[i<<1].mm,T[i<<1|1].mm);}void build(LL i,LL l,LL r){T[i].l=l;T[i].r=r;if(l==r){T[i].mm=0;return ;}LL mid=(l+r)>>1;build(i<<1,l,mid);build(i<<1|1,mid+1,r);pushup(i);}void updata(LL i,LL x,LL v){LL l=T[i].l;LL r=T[i].r;if(l==r){T[i].mm=v;return ;}LL mid=(l+r)>>1;if(x<=mid)updata(i<<1,x,v);else updata(i<<1|1,x,v);pushup(i);}LL query(LL i,LL L,LL R){LL l=T[i].l;LL r=T[i].r;if(l>=L&&r<=R)return T[i].mm;LL mid=(l+r)>>1;LL ans=0;if(L<=mid)ans=max(ans,query(i<<1,L,R));if(R>mid)ans=max(ans,query(i<<1|1,L,R));return ans;}LL cnt;char ss[5];LL n;LL t;int main(){scanf("%lld%lld",&m,&M);cnt=0;t=0;build(1,1,m);for(LL i=1;i<=m;i++){scanf("%s%lld",ss,&n);if(ss[0]=='A'){cnt++;updata(1,cnt,(n+t)%M);}else if(ss[0]=='Q'){t=query(1,cnt-n+1,cnt);printf("%lld\n",t);}}return 0;}


0 0
原创粉丝点击