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 ...
随机推荐
- v2.0
#include <stdio.h>#include <string.h>#include <ctype.h>typedef struct node{ char l ...
- BulletedList使用及详解
BulletedList是一个让你轻松在页面上显示项目符号和编号格式(Bulledted List)的控件.对于ASP.NET 1.x里要动态显示Bulledted List时,要么自己利用HTML的 ...
- 【Android测试】【第十四节】Appium——简述
◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/5124340.html 前言 同样的,这一篇我要介绍的也是一 ...
- ubuntu下的jdk安装
软件环境: 虚拟机:VMware Workstation 10 操作系统:ubuntu-12.04-desktop-amd64 JAVA版本:jdk-7u55-linux-x64 软件下载地址: JD ...
- HttpPost发送Json
1.public static JSONObject post(String url,JSONObject json){ 2. HttpClient client = new DefaultHttpC ...
- logback详细配置(三)
转自:http://blog.csdn.net/haidage/article/details/6794540 <filter>: 过滤器,执行一个过滤器会有返回个枚举值,即DENY,NE ...
- kinect for windows sdk
https://msdn.microsoft.com/library/dn799271.aspx
- ionic build android 报错分析
- python 编码与解码 decode解码 encode 编码
>>> '无' #gbk字符'\xce\xde'>>> str1 = '\xce\xde'>>> str1.decode('gbk') # ...
- yaffs2文件系统镜像分析
概述 yaffs2文件系统镜像通过mkyaffs2img工具制作,由源码可编译出两个镜像工具mkyaffsimage和mkyaffs2image,其中mkyaffsimage是针对yaffs文件系统, ...