(简单) HDU 3308 LCIS,线段树+区间合并。
  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].
题目大意就是给你一个数列,求区间内的最长连续子序列。以及对某一个点的值进行更改。
线段树维护区间内的LCIS,前缀LCIS,后缀LCIS就可。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring> #define lson L,M,po*2
#define rson M+1,R,po*2+1
#define lc po*2
#define rc po*2+1 using namespace std; const int maxn=10e5+; int mBIT[maxn*],lBIT[maxn*],rBIT[maxn*];
int num[maxn]; void pushUP(int po,int len,int M)
{
mBIT[po]=max(mBIT[lc],mBIT[rc]);
lBIT[po]=lBIT[lc];
rBIT[po]=rBIT[rc]; if(num[M]<num[M+])
{
mBIT[po]=max(mBIT[po],rBIT[lc]+lBIT[rc]); if(lBIT[lc]==len-(len/))
lBIT[po]+=lBIT[rc]; if(rBIT[rc]==(len/))
rBIT[po]+=rBIT[lc];
}
} void build_tree(int L,int R,int po)
{
if(L==R)
{
scanf("%d",&num[L]);
mBIT[po]=lBIT[po]=rBIT[po]=; return;
} int M=(L+R)/; build_tree(lson);
build_tree(rson); pushUP(po,R-L+,M);
} void update(int up,int L,int R,int po)
{
if(L==R&&L==up)
return; int M=(L+R)/; if(up<=M)
update(up,lson);
else
update(up,rson); pushUP(po,R-L+,M);
} int query(int ql,int qr,int L,int R,int po)
{
if(ql<=L&&qr>=R)
return mBIT[po]; int M=(L+R)/; if(qr<=M)
return query(ql,qr,lson);
if(ql>M)
return query(ql,qr,rson); int ans=max(query(max(ql,L),M,lson),query(M+,min(qr,R),rson));
int temp=min(rBIT[lc],M-ql+)+min(lBIT[rc],qr-M); if(num[M]<num[M+]) //这里要判断!
return max(ans,temp);
else
return ans;
} int main()
{
int N,M;
int a,b;
char c[];
int T;
cin>>T; while(T--)
{
scanf("%d %d",&N,&M); build_tree(,N-,); while(M--)
{
scanf("%s %d %d",c,&a,&b); if(c[]=='Q')
printf("%d\n",query(a,b,,N-,));
else
{
num[a]=b;
update(a,,N-,);
}
}
} return ;
}
(简单) HDU 3308 LCIS,线段树+区间合并。的更多相关文章
- HDU 3308 LCIS (线段树区间合并)
		
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 题目很好懂,就是单点更新,然后求区间的最长上升子序列. 线段树区间合并问题,注意合并的条件是a[ ...
 - LCIS HDU - 3308 (线段树区间合并)
		
LCIS HDU - 3308 Given n integers. You have two operations: U A B: replace the Ath number by B. (inde ...
 - HDU 3308 (线段树区间合并)
		
http://acm.hdu.edu.cn/showproblem.php?pid=3308 题意: 两个操作 : 1 修改 单点 a 处的值. 2 求出 区间[a,b]内的最长上升子序列. 做法 ...
 - HDU 3308	 LCIS 线段树区间更新
		
最近开始线段树一段时间了,也发现了不少大牛的博客比如HH大牛 ,小媛姐.这个题目是我在看HH大牛的线段树专题是给出的习题,(可以去他博客找找,真心推荐)原本例题是POJ3667 Hotel 这个题目 ...
 - hud 3308 LCIS 线段树 区间合并
		
题意: Q a b 查询[a, b]区间的最长连续递增子序列的长度 U a b 将下表为a的元素更新为b 区间合并一般都有3个数组:区间最值,左区间最值和右区间最值 具体详见代码 #include & ...
 - HDU 3308 LCIS (线段树·单点更新·区间合并)
		
题意 给你一个数组 有更新值和查询两种操作 对于每次查询 输出相应区间的最长连续递增子序列的长度 基础的线段树区间合并 线段树维护三个值 相应区间的LCIS长度(lcis) 相应区间以左 ...
 - hdu-3308 LCIS (线段树区间合并)
		
LCIS Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
 - HDU 3308 LCIS(线段树单点更新区间合并)
		
LCIS Given n integers. You have two operations: U A B: replace the Ath number by B. (index counting ...
 - hdu 3308 LCIS 线段树
		
昨天热身赛的简单版:LCIS.昨天那题用树链剖分,不知道哪里写错了,所以水了水这题看看合并.更新方式是否正确,发现没错啊.看来应该是在树链剖分求lca时写错了... 题目:给出n个数,有两种操作: 1 ...
 - hdu 1540(线段树区间合并)
		
题目链接:传送门 参考文章:传送门 题意:n个数字初始连在一条线上,有三种操作, D x表示x号被摧毁: R 表示恢复剩下的通路 Q表示查询标号为x所在的串的最长长度. 思路:线段树的区间合并. #i ...
 
随机推荐
- POJ3264/RMQ
			
题目链接 /* 询问一段区间内的元素差值最大是多少,用RMQ维护一个最大值和一个最小值,相减即可. */ #include<cstdio> #include<cstring> ...
 - margin:0 auto
			
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
 - Oracle Sql优化之范围处理
			
1.表中字段自关联与分析函数的性能比较,自关联需要扫描表两次,分析函数扫描一次即可 ----自关联 select v1.proj_id,v1.proj_start,v1.proj_end from v ...
 - POJ 2289 Jamie's Contact Groups
			
二分答案+网络最大流 #include<cstdio> #include<cstring> #include<cmath> #include<vector&g ...
 - opencart配置税率
			
1.System->Localisation->Geo Zones新增税收区域 2.System->Localisation->Taxes->Tax Rates新增税率 ...
 - 团队开发里频繁使用 git rebase 来保持树的整洁好吗?
			
用了以后, 树可以非常清晰, 某种程度上便于追踪, 但是 push --force 就多多了,不用呢, 合并没有远程仓库被修改的麻烦, 可是追踪又不清晰... git rebase是对commit h ...
 - win10系统安装oracle11g时遇到INS-13001环境不满足最低要求
			
升级win10系统之后,需要重新安装Oracle,因为在安装Oralce11g时,使用64位的会出现各种不兼容问题,我每次安装都是使用32位的数据库. 在安装时点击setup.exe之后,出现了:[I ...
 - 安装psutil模块报错&安装python-devel
			
psutil/_psutil_linux.c:9:20: 错误:Python.h:没有那个文件或目录 In file included from psutil/_psutil_linux.c:19:p ...
 - 我的android学习脚步----------- Button 和监听器setonclicklistener
			
最基本的学习,设置一个按钮并监听实现实时时刻显示 首先XML布局,在layout中的 activity_main.xml中拖一个Button按钮到相应位置 然后在xml文件中做修改 <Rela ...
 - APK自我保护方法
			
标 题: [原创]APK自我保护方法 作 者: MindMac 时 间: 2013-12-28,21:41:15 链 接: http://bbs.pediy.com/showthread.php?t= ...