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. v2.0

    #include <stdio.h>#include <string.h>#include <ctype.h>typedef struct node{ char l ...

  2. BulletedList使用及详解

    BulletedList是一个让你轻松在页面上显示项目符号和编号格式(Bulledted List)的控件.对于ASP.NET 1.x里要动态显示Bulledted List时,要么自己利用HTML的 ...

  3. 【Android测试】【第十四节】Appium——简述

    ◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/5124340.html 前言 同样的,这一篇我要介绍的也是一 ...

  4. ubuntu下的jdk安装

    软件环境: 虚拟机:VMware Workstation 10 操作系统:ubuntu-12.04-desktop-amd64 JAVA版本:jdk-7u55-linux-x64 软件下载地址: JD ...

  5. HttpPost发送Json

    1.public static JSONObject post(String url,JSONObject json){ 2. HttpClient client = new DefaultHttpC ...

  6. logback详细配置(三)

    转自:http://blog.csdn.net/haidage/article/details/6794540 <filter>: 过滤器,执行一个过滤器会有返回个枚举值,即DENY,NE ...

  7. kinect for windows sdk

    https://msdn.microsoft.com/library/dn799271.aspx

  8. ionic build android 报错分析

  9. python 编码与解码 decode解码 encode 编码

    >>> '无'   #gbk字符'\xce\xde'>>> str1 = '\xce\xde'>>> str1.decode('gbk')  # ...

  10. yaffs2文件系统镜像分析

    概述 yaffs2文件系统镜像通过mkyaffs2img工具制作,由源码可编译出两个镜像工具mkyaffsimage和mkyaffs2image,其中mkyaffsimage是针对yaffs文件系统, ...