HDU 3308 LCIS(线段树)
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).
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXN = << ; int lmax[MAXN], rmax[MAXN], mmax[MAXN];
int a[MAXN], n, m, T; void update(int x, int l, int r, int pos, int val) {
if(pos <= l && r <= pos) {
a[pos] = val;
} else {
int ll = x << , rr = ll | , mid = (l + r) >> ;
if(pos <= mid) update(ll, l, mid, pos, val);
if(mid < pos) update(rr, mid + , r, pos, val);
if(a[mid] < a[mid + ]) {
lmax[x] = lmax[ll] + (lmax[ll] == mid - l + ) * lmax[rr];
rmax[x] = rmax[rr] + (rmax[rr] == r - mid) * rmax[ll];
mmax[x] = max(rmax[ll] + lmax[rr], max(mmax[ll], mmax[rr]));
} else {
lmax[x] = lmax[ll];
rmax[x] = rmax[rr];
mmax[x] = max(mmax[ll], mmax[rr]);
}
}
} int query(int x, int l, int r, int aa, int bb) {
if(aa <= l && r <= bb) {
return mmax[x];
} else {
int ll = x << , rr = ll | , mid = (l + r) >> ;
int ans = ;
if(aa <= mid) ans = max(ans, query(ll, l, mid, aa, bb));
if(mid < bb) ans = max(ans, query(rr, mid + , r, aa, bb));
if(a[mid] < a[mid + ]) ans = max(ans, min(rmax[ll], mid - aa + ) + min(lmax[rr], bb - mid));
return ans;
}
} void build(int x, int l, int r) {
if(l == r) {
lmax[x] = rmax[x] = mmax[x] = ;
} else {
int ll = x << , rr = ll | , mid = (l + r) >> ;
build(ll, l, mid);
build(rr, mid + , r);
if(a[mid] < a[mid + ]) {
lmax[x] = lmax[ll] + (lmax[ll] == mid - l + ) * lmax[rr];
rmax[x] = rmax[rr] + (rmax[rr] == r - mid) * rmax[ll];
mmax[x] = max(rmax[ll] + lmax[rr], max(mmax[ll], mmax[rr]));
} else {
lmax[x] = lmax[ll];
rmax[x] = rmax[rr];
mmax[x] = max(mmax[ll], mmax[rr]);
}
}
} int main() {
scanf("%d", &T);
while(T--) {
scanf("%d%d", &n, &m);
for(int i = ; i < n; ++i) scanf("%d", &a[i]);
build(, , n - );
while(m--) {
char c;
int a, b;
scanf(" %c%d%d", &c, &a, &b);
if(c == 'Q') printf("%d\n", query(, , n - , a, b));
else update(, , n - , a, b);
}
}
}
HDU 3308 LCIS(线段树)的更多相关文章
- HDU 3308 LCIS (线段树区间合并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 题目很好懂,就是单点更新,然后求区间的最长上升子序列. 线段树区间合并问题,注意合并的条件是a[ ...
- 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长度(lcis) 相应区间以左 ...
- HDU 3308 LCIS 线段树区间更新
最近开始线段树一段时间了,也发现了不少大牛的博客比如HH大牛 ,小媛姐.这个题目是我在看HH大牛的线段树专题是给出的习题,(可以去他博客找找,真心推荐)原本例题是POJ3667 Hotel 这个题目 ...
- hdu 3308 LCIS 线段树
昨天热身赛的简单版:LCIS.昨天那题用树链剖分,不知道哪里写错了,所以水了水这题看看合并.更新方式是否正确,发现没错啊.看来应该是在树链剖分求lca时写错了... 题目:给出n个数,有两种操作: 1 ...
- HDU 3308 LCIS(线段树)
题目链接 模板题吧,忘了好多,终于A了... #include <cstring> #include <cstdio> #include <string> #inc ...
- 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]内的最长上升子序列. 做法 ...
- hud 3308 LCIS 线段树 区间合并
题意: Q a b 查询[a, b]区间的最长连续递增子序列的长度 U a b 将下表为a的元素更新为b 区间合并一般都有3个数组:区间最值,左区间最值和右区间最值 具体详见代码 #include & ...
- hdu 4031 attack 线段树区间更新
Attack Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Subm ...
随机推荐
- CC2541连接BTool教程
一.简介 本篇介绍如何基于Smart RF(主芯片CC2541).Smart RF(主芯片CC2540).Usb Dongle,来使用软件BTool. 本篇暂时只介绍如何连接,不介绍如何使用BTool ...
- 我的第一个chrome扩展(3)——继续读样例
1.操作用户正在浏览的界面 http://www.ituring.com.cn/article/60212 问题:1.google未定义ID,用name为何无法找到? 2.如何让整个按钮一起动?原函数 ...
- 我的第一个chrome扩展(0)——目标
当前有两个方向: 一.实现一个自动解码的地址栏监视器 扩展程序在后台不断监视地址栏输入,地址栏输入并回车后检查输入,若输入符合解码条件则调用网站信息进行解码,并将结果输出到地址栏,否则不改变: 初始阶 ...
- php mongodb类
class HMongodb { private $mongo; //Mongodb连接 private $curr_db_name; private $curr_table_nam ...
- Windows下git使用代理服务器的设置方法
在我朝独有的无敌GFW关照下(当然,也有可能IP被网站封了),要下载网络上开源的软件是非常困难的一件事情,在这种情况下,使用VPN或者代理服务器就非常有必要了.对于单个应用FQ来说,个人比较喜欢用FQ ...
- 是什么在.NET程序关闭时阻碍进程的退出?
在平时使用软件或是.NET程序开发的过程中,我们有时会遇到程序关闭后但进程却没有退出的情况,这往往预示着代码中有问题存在,不能正确的在程序退出时停止代码执行和销毁资源.这个现象有时并不容易被察觉,但在 ...
- Using Change Management and Change Control Within a Project
In any project, change is inevitable whether it comes from within the project or from external sourc ...
- centos 6.4 安装视频解码器
cd /etc/yum.repos.d/ wget http://mirrors.163.com/.help/CentOS6-Base-163.repo yum update rpm -Uhv htt ...
- Java学习-017-EXCEL 文件读取实例源代码
众所周知,EXCEL 也是软件测试开发过程中,常用的数据文件导入导出时的类型文件之一,此文主要讲述如何通过 EXCEL 文件中 Sheet 的索引(index)或者 Sheet 名称获取文件中对应 S ...
- JQuery:JQuery操作CSS类
JQuery:CSS类jQuery - 获取并设置 CSS 类,通过 jQuery,可以很容易地对 CSS 元素进行操作.jQuery 操作 CSSjQuery 拥有若干进行 CSS 操作的方法.我们 ...