转自`Wind
题意:Given n integers.
You have two 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].
分析:区间合并类线段树。
las[maxn<<2] 区间左端起最长的序列长度
ras[maxn<<2] 区间右端起最长的序列长度
mov[maxn<<2] 区间最优值
好像12年省赛题差不多
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define havemid int m=(l+r)>>1
#define left (rt<<1)
#define right (rt<<1|1)
const int maxn=100100;
int las[maxn<<2];
int ras[maxn<<2];
int mov[maxn<<2];
int va[maxn<<2];
void pushup(int l,int r,int m,int rt){
las[rt]=las[left];
ras[rt]=ras[right];
mov[rt]=0;
if(va[m]<va[m+1]){
mov[rt]=ras[left]+las[right];
if(las[rt]==m-l+1)las[rt]+=las[right];
if(ras[rt]==r-m)ras[rt]+=ras[left];
}
mov[rt]=max(mov[rt],max(mov[left],mov[right]));
}
void build(int l,int r,int rt){
if(l==r){
scanf("%d",&va[l]);
mov[rt]=las[rt]=ras[rt]=1;
return ;
}
havemid;
build(lson);
build(rson);
pushup(l,r,m,rt);
}
void update(int p,int x,int l,int r,int rt){
if(l==r){
va[l]=x;
return ;
}
havemid;
if(p<=m)update(p,x,lson);
else update(p,x,rson);
pushup(l,r,m,rt);
}
int query(int L,int R,int l,int r,int rt){
if(L<=l&&r<=R){
return mov[rt];
}
havemid;
if(R<=m)return query(L,R,lson);
else if(L>m)return query(L,R,rson);
else {
int tmp=0;
if(va[m]<va[m+1])
tmp=min(ras[left],m-L+1)+min(las[right],R-m);
int t1=query(L,R,lson);
int t2=query(L,R,rson);
int ret=max(tmp,max(t1,t2));
return ret;
}
}
int main(){
int T,n,m,a,b;
char s[10];
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
build(1,n,1);
while(m--){
scanf("%s",s);
scanf("%d%d",&a,&b);
if(s[0]=='Q')printf("%d\n",query(a+1,b+1,1,n,1));
else update(a+1,b,1,n,1);
}
}
return 0;
}
本文介绍了一种基于线段树的数据结构实现方法,用于解决包含区间更新与查询最长连续递增子序列的问题。该算法利用了特殊的节点属性来优化查询效率,并提供了完整的C++代码实现。
转自`Wind&spm=1001.2101.3001.5002&articleId=8902318&d=1&t=3&u=093d290550dd4114b54be5fc0d78779d)

被折叠的 条评论
为什么被折叠?



