bzoj4491, I don't know what the title is.

Source: Internet
Author: User

Description

Given a sequence a[i], each query l,r, to [L,r] the oldest string, so that the substring is not ascending substring or no descent substring

Input

The first row, N, indicates how many elements of a array
The next line is n integers a[i]
Next an integer q that indicates the number of queries
Next Q line, 2 integers per line l,r

Output

For each query, ask for the oldest string within [L,r], so that the substring is not ascending substring or not descending substring

It is convenient to combine interval information by using segment tree to maintain the longest monotone substring length, left and right endpoint value, and the longest monotone non-decrement/non-increment string length of the left and

#include <cstdio>inlineintRead () {intx=0, C=getchar (), f=1;  while(c>'9'|| c<'0'){if(c=='-') f=-1; c=GetChar ();}  while(c>='0'&&c<='9') x=x*Ten+c-'0', c=GetChar (); returnx*F;}Const intn=132000;intP,PV;intn,q;intLv[n],rv[n],mx[n],li[n],ld[n],ri[n],rd[n],sz[n],l,r;inlineintMaxintAintb) {returnA>b?a:b;} InlinevoidUpdintWintLcintRC) {Sz[w]=sz[lc]+SZ[RC]; MX[W]=Max (MX[LC],MX[RC]); LV[W]=lv[lc];rv[w]=RV[RC]; LI[W]=li[lc];ld[w]=LD[LC]; RI[W]=ri[rc];rd[w]=RD[RC]; if(rv[lc]<=LV[RC]) {Mx[w]=max (mx[w],ri[lc]+LI[RC]); if(LI[LC]==SZ[LC]) Li[w]=max (li[w],li[lc]+LI[RC]); if(RI[RC]==SZ[RC]) Ri[w]=max (ri[w],ri[lc]+RI[RC]); }    if(rv[lc]>=LV[RC]) {Mx[w]=max (mx[w],rd[lc]+LD[RC]); if(LD[LC]==SZ[LC]) Ld[w]=max (ld[w],ld[lc]+LD[RC]); if(RD[RC]==SZ[RC]) Rd[w]=max (rd[w],rd[lc]+RD[RC]); }}void Get(intw=1,intL=1,intR=65536){    if(l<=l&&r<=R) {        if(PV) {upd (p,pv,w); PV=p++; }Elsepv=W; return; }    intM=l+r>>1; if(l<=m)Get(w<<1, l,m); if(r>m)Get(w<<1^1, m+1, R);}intMain () {n=read ();  for(intI=1; i<=n;++i) {        intu=i+65535; Lv[u]=rv[u]=read (); Mx[u]=sz[u]=li[u]=ld[u]=ri[u]=rd[u]=1; }     for(intI=65535; i;--i) {        intlc=i<<1, rc=lc^1;    UPD (I,LC,RC); } q=read () +1;  while(--q) {L=read (); r=read (); P=131072;p v=0; Get(); printf ("%d\n", MX[PV]); }    return 0;}

bzoj4491, I don't know what the title is.

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.