hdu-3308 LCIS (线段树区间合并)
LCIS
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8337 Accepted Submission(s): 3566
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].
Each case starts with two integers n , m(0<n,m<=105).
The next line has n integers(0<=val<=105).
The next m lines each has an operation:
U A B(0<=A,n , 0<=B=105)
OR
Q A B(0<=A<=B< n).
10 10
7 7 3 3 5 9 9 8 1 8
Q 6 6
U 3 4
Q 0 1
Q 0 5
Q 4 7
Q 3 5
Q 0 2
Q 4 6
U 6 10
Q 0 9
1
4
2
3
1
2
5
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define mid int m = (l + r) >> 1
const int M = 2e5+;
int lsum[M<<],sum[M<<],rsum[M<<],num[M];
void pushup(int l,int r,int rt){
int k = r - l + ;
mid;
lsum[rt] = lsum[rt<<]; rsum[rt] = rsum[rt<<|];
sum[rt] = max(sum[rt<<],sum[rt<<|]);
if(num[m] < num[m+]){
if(lsum[rt] == (k - (k >> ))) lsum[rt] += lsum[rt<<|];
if(rsum[rt] == (k>>)) rsum[rt] += rsum[rt<<];
sum[rt] = max(sum[rt],lsum[rt<<|]+rsum[rt<<]);
}
}
void build(int l,int r,int rt){
if(l == r){
sum[rt] = lsum[rt] = rsum[rt] = ;
return ;
}
mid;
build(lson);
build(rson);
pushup(l,r,rt);
}
void update(int p,int c,int l,int r,int rt){
if(l == r){
num[l] = c;
return ;
}
mid;
if(p <= m) update(p,c,lson);
if(p > m) update(p,c,rson);
pushup(l,r,rt);
}
int query(int L,int R,int l,int r,int rt){
if(L <= l&&R >= r) return sum[rt];
int ret = ;
mid;
if(L <= m) ret = max(ret,query(L,R,lson));
if(R > m) ret = max(ret,query(L,R,rson));
if(num[m] < num[m+]){
ret = max(ret,min(m - L + ,rsum[rt<<])+min(R-m,lsum[rt<<|]));
}
return ret;
} int main(){
int t,n,q,x,y;
char c;
scanf("%d",&t);
while(t--){
cin>>n>>q;
for(int i = ; i <= n;i ++){
cin>>num[i];
}
build(,n,);
for(int i = ;i < q;i ++){
cin>>c>>x>>y;
if(c == 'Q'){
x++;y++;
cout<<query(x,y,,n,)<<endl;
}
else{
x++;
update(x,y,,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 Given n integers. You have two operations: U A B: replace the Ath number by B. (index counting ...
- hdu 1540(线段树区间合并)
题目链接:传送门 参考文章:传送门 题意:n个数字初始连在一条线上,有三种操作, D x表示x号被摧毁: R 表示恢复剩下的通路 Q表示查询标号为x所在的串的最长长度. 思路:线段树的区间合并. #i ...
- hdu 3308 LCIS 线段树
昨天热身赛的简单版:LCIS.昨天那题用树链剖分,不知道哪里写错了,所以水了水这题看看合并.更新方式是否正确,发现没错啊.看来应该是在树链剖分求lca时写错了... 题目:给出n个数,有两种操作: 1 ...
随机推荐
- 初试Shell脚本
背景 临上线前测试比较努力,遇到闪退或者其他问题,会把日志包打给我,由于app内存限制,目前每次打包都是1m大小,所以有时查找问题的上下文比较吃力.同时由于日志比较多,根据关键词过滤的需求越来越重要. ...
- Navicat连接mysql报错1251
Navicat无法连接MySQL8,是因为MySQL8的方式和MySQL5的加密方式不一样导致 解决方案: 1.通过命令行进入mysql数据库: C:\Windows\system32> mys ...
- windows 平台安装 ffmpeg
一.从https://ffmpeg.zeranoe.com/builds/中下载ffmpeg的static版本: 二.将下载下来的“ffmpeg-4.0.2-win64-static.zip”解压到任 ...
- yocto-sumo源码解析(十): ProcessServer.idle_commands
这一节开始介绍ProcessServer.idle_commands,前面我们知道ProcessServer.main就是不停调用idle_commands()以获取可用的套接字描述符或者是文件描述符 ...
- docker usage
docker ps -a 查看物理机上面所有容器信息列表 docker exec -it $docker_id /bin/bash 进入容器以默认帐号 docker exec -it -u root ...
- Cocos2dx源码赏析(1)之启动流程与主循环
Cocos2dx源码赏析(1)之启动流程与主循环 我们知道Cocos2dx是一款开源的跨平台游戏引擎,而学习开源项目一个较实用的办法就是读源码.所谓,"源码之前,了无秘密".而笔者 ...
- bitcoin PoW原理及区块创建过程
bitcoin PoW原理及区块创建过程 PoW 为了在点对点的基础上实现一个分布式时间戳服务器,我们需要使用PoW(Proof of Work)系统来达成共识.PoW过程就是寻找一个目标值的过程,当 ...
- virtual box下安装ubuntu经验
1. 哪怕下载的是ubuntu64位版本,也在vitualbox下选择ubuntu而不要选择ubuntu(64bit) 2. 安装VBoxGuestAdditional.iso:下载和vbox版本相匹 ...
- Redux和React-Redux的实现(二):Provider组件和connect的实现
接着上一篇讲,上一篇我们实现了自己的Redux和介绍了React的context以及Provider的原理. 1. Provider组件的实现 Provider组件主要有以下下两个作用 在整个应用上包 ...
- sprint2(第六天)
昨天休息一天,今天继续做任务. 燃尽图: