https://www.lydsy.com/JudgeOnline/problem.php?id=1012
https://www.luogu.org/problemnew/show/P1198
Now ask you to maintain a sequence, the following two operations are required: 1, query operation. Syntax: Q l Function: Query the end of the current sequence of L
The largest number in the number, and outputs the value of the number. Limit: l does not exceed the length of the current series. 2, insert operation. Syntax: a n function: N Plus
On 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 taken to a fixed constant d
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 there is no
Number.
The St table can be inverted.
(Of course, the balance tree ah dynamic line of the tree, ah can do, choose the simplest to do.) )
Rokua data It's disgusting, if you're tle, you might as well compare it with the main function.
#include <cstdio>#include<cctype>#include<cstring>#include<cmath>#include<algorithm>#include<iostream>using namespaceStd;typedefLong Longll;Const intn=4e5+5;Const intb= -; inlineintRead () {intx=0, w=0;CharCh=0; while(!isdigit (CH)) {w|=ch=='-'; ch=GetChar ();} while(IsDigit (CH)) X= (x<<3) + (x<<1) + (ch^ -), ch=GetChar (); returnw?-x:x;} ll Dp[n][b+4];intLg[n];Chars[101];inline ll Qry (intLintR) { if(L>r)return 0; inth=lg[r-l+1]; returnMax (dp[r][h],dp[l+ (1<<H)-1][h]);}intMain () {intM=read (), D=read (), n=0; ll t=0, K; lg[1]=0; while(m--) {scanf ("%s%lld",s,&k); if(s[0]=='Q') {printf ("%lld", T=qry (n-k+1, N)); Putchar (Ten); } if(s[0]=='A') {k= (k+t)%D; dp[++n][0]=K; if(n!=1) {Lg[n]=lg[n-1]; if((1<<lg[n]+1) ==n) lg[n]++; } for(intj=1; j<=lg[n];j++){ if(N-(1<<J) +1<1) Break; DP[N][J]=max (dp[n][j-1],dp[n-(1<<j-1)][j-1]); } } } return 0;}
+++++++++++++++++++++++++++++++++++++++++++
+ This article luyouqi233. +
+ Welcome to visit my blog: http://www.cnblogs.com/luyouqi233/ +
+++++++++++++++++++++++++++++++++++++++++++
BZOJ1012:[JSOI2008] Maximum number--