HDU 3308 LCIS(区间合并)转自`Wind
来源:互联网 发布:淘宝刷单平台推荐 编辑:程序博客网 时间:2024/05/20 19:47
转自`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;}
- HDU 3308 LCIS(区间合并)转自`Wind
- hdu 3308 LCIS(区间合并)
- hdu 3308 LCIS(区间合并)
- hdu 3308 LCIS (区间合并)
- hdu 3308 LCIS(单点更新,区间合并)
- hdu 3308 LCIS (线段树+单点更新+区间合并)
- 【HDU】3308 LCIS (线段树-区间合并)
- HDU 3308 LCIS(线段树区间合并)
- HDU - 3308 - LCIS (线段树 - 区间合并)
- HDU 3308 LCIS(线段树区间合并)
- HDU 3308 LCIS(线段树区间合并 单点更新)
- HDU 3308 LCIS(区间合并 + 单点更新)
- HDU 3308 LCIS (线段树区间合并)
- hdu 3308 LCIS(线段树区间合并)
- HDU 3308 - LCIS(线段树+区间合并)
- hdu 3308 LCIS (线段树区间合并)
- HDU 3308 LCIS(线段树的区间合并)
- hdu 3308 LCIS(运用push_up区间合并)
- 关于将ssh项目移植到weblogic上时出现:ClassNotFoundException:org.hibernate.hql.internal.ast.HqlToken(hibernate4)
- Android之Adapter用法总结
- C语言指针强制类型转
- linux内核栈与用户栈
- HDU-3006The Number of set
- HDU 3308 LCIS(区间合并)转自`Wind
- 防止java反编译的一些常用方法
- 使用C++编写的查找字符子串并替换
- Oracle维护常用SQL语句(查询系统表和视图)
- mkimage使用详解
- qq消息发射器
- Cocos2d-x 粒子系统----实现下雪效果
- 双边滤波Matlab实现<The Bilateral Filter>
- 一个比较通用简单易用的配置功能