LCIS

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8337    Accepted Submission(s): 3566

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.
 
Sample Input
1
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
 
Sample Output
1
1
4
2
3
1
2
5
 
Author
shǎ崽
 
思路:
n个数字,q个操作,有两种操作:1.Q询问操作:在x,y区间内最长的连续递增子序列的长度。2,替换操作,把下标为x数替换为y.
这种询问,单点更新操作一般都是用线段树做。之前一直想成了最长递增子序列。。。完全没有思路,,其实他只要求最长的连续子串长度。。注意:是最长的连续的子串。
这样就是很裸的线段树区间合并了,
 
实现代码:
#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 (线段树区间合并)的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  8. hdu 1540(线段树区间合并)

    题目链接:传送门 参考文章:传送门 题意:n个数字初始连在一条线上,有三种操作, D x表示x号被摧毁: R 表示恢复剩下的通路 Q表示查询标号为x所在的串的最长长度. 思路:线段树的区间合并. #i ...

  9. hdu 3308 LCIS 线段树

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

随机推荐

  1. Fiddler 抓包浅析

    Fiddler 工具浅析 Fiddler 是位于客户端和服务器端的 HTTP 代理,也是目前最常用的 HTTP 抓包工具之一.(Mac OS 建议采用 Charles) 它可以记录客户端和服务器之间的 ...

  2. [Codeforces-911B] - Two Cakes

    B. Two Cakestime limit per test 1 secondmemory limit per test 256 megabytesinput standard inputoutpu ...

  3. windows c++如何使窗口动态改变位置

    在windows软件中,经常会碰到一个功能:鼠标hover在某个地方时会出现窗口,有时候这个窗口的位置是会动态调整的. 熟悉使用windows API,理解windows中虚拟坐标.工作区坐标.屏幕坐 ...

  4. Linux(Contos7.5)环境搭建之Gitblit安装(三)

    1.yum安装git(这一步暂时不清楚是否必要,因为在window上搭建并不需要)

  5. 君学,佳一tvodp文件破解

    tvodp文件破解的意思就是,越过加密部分直接提取内部原始文件,难度较大,方法用U盘刻老毛桃pe,然后电脑启动pe,在pe中打开文件,做提取工作, 本人淘宝破解:https://item.taobao ...

  6. Python数据分析工具库-Numpy 数组支持库(一)

    1 Numpy数组 在Python中有类似数组功能的数据结构,比如list,但在数据量大时,list的运行速度便不尽如意,Numpy(Numerical Python)提供了真正的数组功能,以及对数据 ...

  7. Django之Models与ORM操作

    一.models例子 from django.db import models class User(models.Model): """ 用户表 "" ...

  8. 2-Third Scrum Meeting-20151203

    任务安排 闫昊: 今日完成:请假.(编译+计组,压力有点大) 明日任务:设计本地数据库. 唐彬: 今日完成:请假.(编译+计组,压力有点大) 明日任务:阅读ios客户端代码. 史烨轩: 今日完成:请假 ...

  9. TCP系列54—拥塞控制—17、AQM及ECN

    一.概述 ECN的相关内容是在RFC3168中定义的,这里我简单描述一下RFC3168涉及的主要内容. 1.AQM和RED 目前TCP中多数的拥塞控制算法都是通过缓慢增加拥塞窗口直到检测到丢包来进行慢 ...

  10. .NET 类库研究必备参考 扣丁格鲁

    .NET 类库的强大让我们很轻松的解决常见问题,作为一个好专研的程序员,为了更上一层楼,研究CLR的基础类库实现是快速稳定的捷径. 一般场景下,采用 Reflector可以反射出.NET 的部分实现出 ...