https://www.lydsy.com/JudgeOnline/problem.php?id=1012
Now ask you to maintain a sequence, the following two operations are required: 1, query operation. Syntax: Q L function: Query the maximum number of L in the number of the end of the current sequence and output the value of this number. Limit: l does not exceed the length of the current series. 2, insert operation. Syntax: a n function: N plus t, where T is the answer to the most recent query operation (t=0 if the query operation has not been performed), and the resulting result is modeled on a fixed constant d and the resulting answer is inserted at the end of the sequence. Limit: N is a non-negative integer and is within a long range. Note: The initial sequence is empty and does not have a number.
Force online, line tree update can
//#pragma COMMENT (linker, "/stack:200000000")//#pragma GCC optimize ("Ofast,no-stack-protector")//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")//#pragma GCC optimize ("Unroll-loops")#include <bits/stdc++.h>#defineFi first#defineSe Second#defineMP Make_pair#definePB Push_back#definePi ACOs (-1.0)#definell Long Long#defineMoD 1000000007#defineC 0.5772156649#defineLS l,m,rt<<1#defineRS M+1,r,rt<<1|1#definePiL pair<int,ll>#definePLI pair<ll,int>#definePII pair<int,int>#defineCD complex<double>#defineull unsigned long Long#defineBase 1000000000000000000#defineFio Ios::sync_with_stdio (false); Cin.tie (0)using namespacestd;Const Doubleg=10.0, eps=1e- A;Const intn=200000+Ten, maxn=8000000+Ten, inf=0x3f3f3f3f, inf=0x3f3f3f3f3f3f3f3f;structsegtree{ll Ma[n<<2]; voidBuildintLintRintRT) {Ma[rt]=-1; if(L==R)return ; intM= (l+r) >>1; Build (LS); build (RS); } voidUpdateintPos,ll x,intLintRintRT) { if(l==R) {Ma[rt]=x; return ; } intM= (l+r) >>1; if(pos<=m) update (POS,X,LS); ElseUpdate (POS,X,RS); MA[RT]=max (ma[rt<<1],ma[rt<<1|1]); } ll query (intLintRintLintRintRT) { if(L<=L&&R<=R)returnMa[rt]; intM= (l+r) >>1; ll ans=-1; if(l<=m) ans=Max (Ans,query (L,r,ls)); if(M<r) ans=Max (Ans,query (L,r,rs)); returnans; }}tree;intMain () {ll m,d;scanf ("%lld%lld",&m,&d); intn=200000; Tree.build (1N1); LL now=0, ans=0; while(m--) { Charop[5];ll x; scanf ("%s%lld",op,&x); if(op[0]=='A') {ll te= (X+ans)%D; now++; Tree.update (Now,te,1N1); } Else{ans=tree.query (now-x+1, now,1N1); printf ("%lld\n", ans); } } return 0;}/****************************************/
View Code
1012: [JSOI2008] Maximum number of MaxNumber segment tree