Simple HDU 3308 LCIs, Segment tree + interval merge.

Source: Internet
Author: User

Problem Description

Given n integers.
You have both operations:
U A B:replace The Ath number by B. (index counting from 0)
Q A b:output The length of the longest consecutive increasing subsequence (LCIs) in [A, B].

The main idea is to give you a series, the longest continuous sub-sequence within the interval. And a change to the value of a point.

Segment Tree maintenance interval of lcis, prefix lcis, suffix lcis can be.

The code is as follows:

#include <iostream>#include<cstdio>#include<cstring>#defineLson l,m,po*2#defineRson m+1,r,po*2+1#defineLC Po*2#defineRC Po*2+1using namespacestd;Const intmaxn=10e5+Ten;intmbit[maxn*4],lbit[maxn*4],rbit[maxn*4];intNUM[MAXN];voidPushup (intPointLenintM) {Mbit[po]=Max (MBIT[LC],MBIT[RC]); LBIT[PO]=LBIT[LC]; RBIT[PO]=RBIT[RC]; if(num[m]<num[m+1]) {Mbit[po]=max (mbit[po],rbit[lc]+LBIT[RC]); if(Lbit[lc]==len-(len/2)) Lbit[po]+=LBIT[RC]; if(rbit[rc]== (len/2)) Rbit[po]+=RBIT[LC]; }}voidBuild_tree (intLintRintPO) {    if(l==R) {scanf ("%d",&Num[l]); MBIT[PO]=lbit[po]=rbit[po]=1; return; }    intM= (L+R)/2;    Build_tree (Lson);    Build_tree (Rson); Pushup (Po,r-l+1, M);}voidUpdateintUpintLintRintPO) {    if(l==r&&l==Up )return; intM= (L+R)/2; if(up<=M) Update (Up,lson); ElseUpdate (Up,rson); Pushup (Po,r-l+1, M);}intQueryintQlintQrintLintRintPO) {    if(ql<=l&&qr>=R)returnMbit[po]; intM= (L+R)/2; if(qr<=M)returnquery (Ql,qr,lson); if(ql>M)returnquery (Ql,qr,rson); intAns=max (Query (max (ql,l), M,lson), query (m+1, Min (qr,r), Rson)); intTemp=min (rbit[lc],m-ql+1) +min (lbit[rc],qr-l); if(num[m]<num[m+1])//here to judge!         returnMax (ans,temp); Else        returnans;}intMain () {intn,m; intb; Charc[5]; intT; CIN>>T;  while(t--) {scanf ("%d%d",&n,&M); Build_tree (0, N-1,1);  while(m--) {scanf ("%s%d%d",c,&a,&b); if(c[0]=='Q') printf ("%d\n", query (A, B,0, N-1,1)); Else{Num[a]=b; Update (A,0, N-1,1); }        }    }    return 0;}
View Code

Simple HDU 3308 LCIs, Segment tree + interval merge.

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.