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. .net中 多线程 笔记(基础)

    1. 在进程中可以有多个线程同时执行代码.进程之间是相对独立的,一个进程无法访问另一个进程的数据(除非利用分布式计算方式),一个进程运行的失败也不会影响其他进程的运行,Windows系统就是利用进程把 ...

  2. 使用tensorflow进行mnist数字识别【模型训练+预测+模型保存+模型恢复】

      import sys,os sys.path.append(os.pardir) import numpy as np from tensorflow.examples.tutorials.mni ...

  3. PHP核心技术——异常和错误处理

    PHP只有手动抛出异常后才能捕获异常 $a = null; try { $a = 5/0; echo $a,PHP_EOL; } catch (exception $e) { $e -> get ...

  4. Netty源码分析第8章(高性能工具类FastThreadLocal和Recycler)---->第4节: recycler中获取对象

    Netty源码分析第八章: 高性能工具类FastThreadLocal和Recycler 第四节: recycler中获取对象 这一小节剖析如何从对象回收站中获取对象: 我们回顾上一小节demo的ma ...

  5. yocto-sumo源码解析(十一): recvfds

    def recvfds(sock, size): '''Receive an array of fds over an AF_UNIX socket.''' a = array.array('i') ...

  6. 【Kubernetes】基于角色的权限控制:RBAC

    Kubernetes中所有的API对象,都保存在Etcd里,对这些API对象的操作,一定都是通过访问kube-apiserver实现的,原因是需要APIServer来做授权工作. 在Kubernete ...

  7. 时间戳使用的bug,你见过么

    博主本人前几天给公司项目里写了个禁言和解除禁言的功能,项目中涉及到对时间的处理,因为学得时候也没很注意,就按自己的思路去写了,运行起来发现了一个天大的bug,就是写的延后一年尽然,刚开始就执行了,而且 ...

  8. SecureCRT SSH连接一直提示密码错误

    这是解决方法:  http://www.linuxidc.com/Linux/2016-09/134925.htm

  9. 20135337朱荟潼Java实验报告二

    20135337朱荟潼 实验二 Java面向对象程序设计 一.实验内容 1. 初步掌握单元测试和TDD 2. 理解并掌握面向对象三要素:封装.继承.多态 3. 初步掌握UML建模 4. 熟悉S.O.L ...

  10. 场景调研 persona

    1.姓名:王涛 2.年龄:22 3.收入:基本无收入 4.代表用户在市场上的比例和重要性:王涛为铁道学生.本软件的用户主要是学生和老师,尤其是广大的铁大学子,所以此典型用户的重要性不言而喻,而且比例相 ...