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].
Input
T in the first line, indicating the case number.
Each case is starts with a integers n, m (0<n,m<=10 5).
The next line has n integers (0<=val<=10 5).
The next m lines each have an operation:
U A B (0<=a,n, 0<=b=10 5)
OR
Q A B (0<=a<=b< N).
Output
For each Q, output the answer.
Sample Input
107 7 3 3 5 9 9 8 1 8 Q 6 6U 3 4Q 0 1Q 0 5Q 4 7Q 3 5Q 0 2Q 4 6U 6 10Q 0 9
Sample Output
11423125
Test instructions: Give a column n number, perform m operations, change the value of a to B, query the length of the longest continuous ascending subsequence between [A, b], and output the result for each query
Idea: Use a segment tree to save the maximum length of the current node and the length of the left start and end of the right, and then update up. The query is the same as the query in the line tree, which is to pay attention to the updates to the left and right boundaries when querying.
AC Code:
1#include <iostream>2#include <fstream>3#include <iomanip>4#include <cstdio>5#include <cstring>6#include <algorithm>7#include <cstdlib>8#include <cmath>9#include <Set>Ten#include <map> One#include <queue> A#include <stack> -#include <string> -#include <vector> the#include <ctime> -#include <sstream> -#include <cassert> - using namespacestd; + Const intmaxn=100005; - structNote + { A intl,r,lm,rm,m; at} a[maxn<<2]; - intP[MAXN]; - intBuildintLintRintk) - { -A[k].l=l; -A[k].r=R; ina[k].lm=a[k].rm=a[k].m=0; - if(l==R) to { + return 0; - } the intMid= (L+R)/2; *Build (l,mid,k*2); $Build (mid+1, r,k*2+1);Panax Notoginseng return 0; - } the intPushup (intk) + { A if(p[a[k*2].r]>=p[a[k*2+1].L]) the { +A[k].m=max (a[k*2].m,a[k*2+1].m); -a[k].lm=a[k*2].lm; $a[k].rm=a[k*2+1].rm; $ } - Else - { theA[k].m=max (Max (a[k*2].rm+a[k*2+1].lm,a[k*2].M), a[k*2+1].m); - if(a[k*2].lm== (a[k*2].r-a[k*2].l+1))Wuyia[k].lm=a[k*2].lm+a[k*2+1].lm; the Else -a[k].lm=a[k*2].lm; Wu if(a[k*2+1].rm== (a[k*2+1].r-a[k*2+1].l+1)) -a[k].rm=a[k*2].rm+a[k*2+1].rm; About Else $a[k].rm=a[k*2+1].rm; - } - return 0; - } A intInsintNintDintk) + { the if(a[k].l==a[k].r&&a[k].l==d) - { $a[k].rm=a[k].lm=a[k].m=1; the return 0; the } the if(a[k*2].r>=d) Ins (n,d,k*2); the Else if(a[k*2+1].l<=d) Ins (n,d,k*2+1); - Pushup (k); in return 0; the } the intSeaintLintRintk) About { the if(l==a[k].l&&a[k].r==R) the { the returna[k].m; + } - if(a[k*2].R>=R)returnSea (l,r,k*2); the Else if(a[k*2+1].L<=L)returnSea (l,r,k*2+1);Bayi Else the { the intT1=sea (l,a[k*2].r,k*2); - intT2=sea (a[k*2+1].l,r,k*2+1); - intans=Max (T1,T2); the intsum=0; the if(p[a[k*2].r]<p[a[k*2+1].L]) theSum=min (a[k*2].r-l+1, a[k*2].RM) +min (r-a[k*2].r,a[k*2+1].lm); the returnMax (ans,sum); - } the } the intMain () the {94 intn,m,t,c,b; thescanf"%d",&t); the { the for(intkk=1; kk<=t; kk++)98 { Aboutscanf"%d%d",&n,&m); -Build1N1);101 for(intI=1; i<=n; i++)102 {103scanf"%d",&c);104p[i]=C; theIns (C,i,1);106 }107 Chars[Ten];108 for(intI=0; i<m; i++)109 { thescanf"%s", s);111 if(s[0]=='U') the {113scanf"%d%d",&c,&b); thep[c+1]=b; theINS (b,c+1,1); the }117 Else118 {119scanf"%d%d",&c,&b); -printf"%d\n", Sea (c+1, B +1,1));121 }122 }123 }124 } the return 0;126}
View Code
hdu--3308 LCIs (segment tree + interval merge)