Transmission Door
idea: operand m<=200000, assuming every time is inserted, then the resulting sequence length will not exceed 200000, consider the interval [1,m] Build a line tree, then the board question.
AC Code:
#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;Const intn=200000+ -; typedefLong Longll;inttot;structnode{intL,r; ll Maxx;} Tr[n<<2];voidUpdata (intu) {Tr[u].maxx=max (tr[u<<1].maxx,tr[u<<1|1].maxx);}voidBuildintUintLintR) {TR[U].L=l,tr[u].r=R; if(l==R) {Tr[u].maxx=0;return ; } intMid= (l+r) >>1; Build (U<<1, l,mid); Build (u<<1|1, mid+1, R); Updata (u);}voidModifyintUintp,ll k) { intL=tr[u].l,r=TR[U].R; if(l==R) {Tr[u].maxx=k;return ; } intMid= (l+r) >>1; if(p<=mid) Modify (u<<1, p,k); ElseModify (u<<1|1, p,k); Updata (u);} ll query (intUintQlintqr) {ll ans=-(1<< -); intL=tr[u].l,r=TR[U].R; if(QL<=L&&QR>=R)returnTr[u].maxx; if(ql>r| | QR<L)return-(1<< -); intMid= (l+r) >>1; if(Ql<=mid) Ans=max (Ans,query (u<<1, QL,QR)); if(Qr>mid) Ans=max (Ans,query (u<<1|1, QL,QR)); returnans;} intMain () {intm; ll D; scanf ("%d%lld",&m,&d); Build (1,1, M); Charop[3];ll t=0; for(intI=1; i<=m;i++) {scanf ("%s", op); if(op[0]=='A') {ll n;scanf ("%lld",&N); N= (n+t)%D; Tot++; Modify (1, Tot,n); } Else if(op[0]=='Q'){ intL;SCANF ("%d",&l); intr=tot;l=tot-l+1; T=query (1, L,r); printf ("%lld\n", T); } } return 0;}
P1198 [JSOI2008] Maximum number-segment tree