BZOJ1012:[JSOI2008] Maximum number--

Source: Internet
Author: User

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&LT;&LT;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&LT;&LT;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--

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.