Problem Description
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].
 
Input
T in the first line, indicating the case number.
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).
 
Output
For each Q, output the answer.
 
题目大意:给n个数,动态地修改某个数的值,或者查询一段区间的LCIS(最长连续上升子序列,坑爹的标题……)。
思路:线段树,每个点维护一个区间的从左边开始的最长的LCIS,从右边开始的最长的LCIS,这个区间最大的LCIS。然后随便搞搞就能过了……
 
代码(593MS):
 #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(线段树)的更多相关文章

  1. HDU 3308 LCIS (线段树区间合并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 题目很好懂,就是单点更新,然后求区间的最长上升子序列. 线段树区间合并问题,注意合并的条件是a[ ...

  2. HDU 3308 LCIS(线段树单点更新区间合并)

    LCIS Given n integers. You have two operations: U A B: replace the Ath number by B. (index counting ...

  3. HDU 3308 LCIS (线段树&#183;单点更新&#183;区间合并)

    题意  给你一个数组  有更新值和查询两种操作  对于每次查询  输出相应区间的最长连续递增子序列的长度 基础的线段树区间合并  线段树维护三个值  相应区间的LCIS长度(lcis)  相应区间以左 ...

  4. HDU 3308 LCIS 线段树区间更新

    最近开始线段树一段时间了,也发现了不少大牛的博客比如HH大牛  ,小媛姐.这个题目是我在看HH大牛的线段树专题是给出的习题,(可以去他博客找找,真心推荐)原本例题是POJ3667 Hotel 这个题目 ...

  5. hdu 3308 LCIS 线段树

    昨天热身赛的简单版:LCIS.昨天那题用树链剖分,不知道哪里写错了,所以水了水这题看看合并.更新方式是否正确,发现没错啊.看来应该是在树链剖分求lca时写错了... 题目:给出n个数,有两种操作: 1 ...

  6. HDU 3308 LCIS(线段树)

    题目链接 模板题吧,忘了好多,终于A了... #include <cstring> #include <cstdio> #include <string> #inc ...

  7. LCIS HDU - 3308 (线段树区间合并)

    LCIS HDU - 3308 Given n integers. You have two operations: U A B: replace the Ath number by B. (inde ...

  8. HDU 3308 (线段树区间合并)

    http://acm.hdu.edu.cn/showproblem.php?pid=3308 题意: 两个操作  : 1 修改 单点  a 处的值. 2 求出 区间[a,b]内的最长上升子序列. 做法 ...

  9. hud 3308 LCIS 线段树 区间合并

    题意: Q a b 查询[a, b]区间的最长连续递增子序列的长度 U a b 将下表为a的元素更新为b 区间合并一般都有3个数组:区间最值,左区间最值和右区间最值 具体详见代码 #include & ...

  10. hdu 4031 attack 线段树区间更新

    Attack Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Subm ...

随机推荐

  1. 备份mysql

    #!/bin/bash # 要备份的数据库名,多个数据库用空格分开USER=rootPASSWORD=rootdatabases=("shopnc") # 备份文件要保存的目录ba ...

  2. SWT常用组件(转)

    转载自:http://www.cnblogs.com/happyPawpaw/archive/2012/10/19/2730478.html 1按钮组件(Button) (1)Button组件常用样式 ...

  3. 1012 最小公倍数LCM

    1012 最小公倍数LCM 基准时间限制:1 秒 空间限制:131072 KB 输入2个正整数A,B,求A与B的最小公倍数. Input 2个数A,B,中间用空格隔开.(1<= A,B < ...

  4. AC自动机算法详解

    首先简要介绍一下AC自动机:Aho-Corasick automation,该算法在1975年产生于贝尔实验室,是著名的多模匹配算法之一.一个常见的例子就是给出n个单词,再给出一段包含m个字符的文章, ...

  5. ecshop

    if($cat_id == '205'){ $smarty->display('cat1.dwt', $cache_id); }elseif($cat_id == '2'){ $smarty-& ...

  6. 【转】Android 获得view的宽和高

     转自:http://blog.csdn.net/yangdeli888/article/details/25405263 Android 获得view的宽和高 分类: android 技术点项目20 ...

  7. Web设计者和开发者必备的28个Chrome插件

    摘要 对于许多Web设计者和开发者来说,Firefox浏览器是无法超越的,对于其他人Chrome正在蚕食Firefox的浏览器市场. 在过去的两年,谷歌Chrome浏览器的发布以来,引起了人们激烈争论 ...

  8. 如何在 Linux 中清除缓存(Cache)

              如何在 Linux 中清除缓存(Cache)            方法一: http://mp.weixin.qq.com/s?__biz=MjM5ODAzODgyMQ==&am ...

  9. Android大图片裁剪终极解决方案(上:原理分析)

    转载声明:Ryan的博客文章欢迎您的转载,但在转载的同时,请注明文章的来源出处,不胜感激! :-)  http://my.oschina.net/ryanhoo/blog/86842 约几个月前,我正 ...

  10. C# 实例化多线程组

    代码如下 //实例化线程组 Thread[] clientThreads = new Thread[numThread]; ; i < numThread; i++) { clientThrea ...