HDU3308 线段树(区间合并)
LCIS
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7193 Accepted Submission(s): 3069
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).
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
//最大递增子串sub可能是区间[l,r]中前缀部分,后缀部分或者中间部分(横跨两个子区间)。
//线段树维护信息:val(表节点的值),sub(最长上升子序列的长度),pre(最
//长上升前缀的长度),suf(最长上升后缀的长度).由于一个区间[L,R]内的LCIS,
//可能在左半边,也可能跨越两边,也可能在右半边,
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=;
int val[maxn],suf[maxn*],pre[maxn*],sub[maxn*];
void pushup(int id,int l,int r)
{
int m=(l+r)>>;
sub[id]=max(sub[id<<],sub[id<<|]);
if(val[m]<val[m+]) sub[id]=max(sub[id],suf[id<<]+pre[id<<|]);
//如果两个子区间连续,左子区间后缀+右子区间前缀
pre[id]=pre[id<<];
if((pre[id]==m-l+)&&val[m]<val[m+]) pre[id]+=pre[id<<|];
//如果前缀是左子区间的所有数并且左子区间右边界值小于右子区间左边界值
suf[id]=suf[id<<|];
if((suf[id]==r-m)&&val[m]<val[m+]) suf[id]+=suf[id<<];
//如果后缀是右子区间的所有数并且左子区间右边界值小于右子区间左边界值
}
void build(int id,int l,int r)
{
if(l==r){
sub[id]=suf[id]=pre[id]=;
return;
}
int m=(l+r)>>;
build(id<<,l,m);
build(id<<|,m+,r);
pushup(id,l,r);
}
void update(int a,int b,int id,int l,int r)
{
if(l==r){
val[l]=b;
sub[id]=suf[id]=pre[id]=;
return;
}
int m=(l+r)>>;
if(a<=m) update(a,b,id<<,l,m);
else update(a,b,id<<|,m+,r);
pushup(id,l,r);
}
int query(int ql,int qr,int id,int l,int r)
{
if(ql<=l&&qr>=r) return sub[id];
int m=(l+r)>>;
if(qr<=m) return query(ql,qr,id<<,l,m);
else if(ql>m) return query(ql,qr,id<<|,m+,r);
int subx=max(query(ql,qr,id<<,l,m),query(ql,qr,id<<|,m+,r));
int prex=min(qr-m,pre[id<<|]);//右子区间中在查询范围中的前缀
int sufx=min(m-ql+,suf[id<<]);//左子区间中在查询范围中的后缀
if(val[m]<val[m+]) subx=max(subx,prex+sufx);
return subx;
}
int main()
{
int t,n,m;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) scanf("%d",&val[i]);
build(,,n);
char ch[];int a,b;
while(m--){
scanf("%s%d%d",ch,&a,&b);
if(ch[]=='U') update(a+,b,,,n);
else if(ch[]=='Q') printf("%d\n",query(a+,b+,,,n));
}
}
return ;
}
HDU3308 线段树(区间合并)的更多相关文章
- HDU3308 线段树区间合并
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 ,简单的线段树区间合并. 线段树的区间合并:一般是要求求最长连续区间,在PushUp()函数中实 ...
- LCIS hdu3308 (线段树 区间合并)
题意: 有两种操作 一种是单点改为b 一种是给出区间ab 区间ab的最大上升子序列个数.. 线段树目前学了三种 第一种单点操作很简单 第二种区域操作加上懒惰标记即可 现在这种 为区间合并. ...
- hdu3308 线段树——区间合并
更新一个点: 求某个区间的最长连续上升序列: 链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 #include <cstdio> #in ...
- hdu3308 线段树 区间合并
给n个数字 U表示第A个数改为B.A是从0开始. Q输出最大的递增序列个数. 考虑左边,右边,和最大的. #include<stdio.h> #define lson l,m,rt< ...
- hdu-3308 LCIS (线段树区间合并)
LCIS Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- POJ 3667 Hotel(线段树 区间合并)
Hotel 转载自:http://www.cnblogs.com/scau20110726/archive/2013/05/07/3065418.html [题目链接]Hotel [题目类型]线段树 ...
- HDU 3911 线段树区间合并、异或取反操作
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3911 线段树区间合并的题目,解释一下代码中声明数组的作用: m1是区间内连续1的最长长度,m0是区间内连续 ...
- HDU 3911 Black And White(线段树区间合并+lazy操作)
开始以为是水题,结果...... 给你一些只有两种颜色的石头,0为白色,1为黑色. 然后两个操作: 1 l r 将[ l , r ]内的颜色取反 0 l r 计算[ l , r ]内最长连续黑色石头的 ...
- HYSBZ 1858 线段树 区间合并
//Accepted 14560 KB 1532 ms //线段树 区间合并 /* 0 a b 把[a, b]区间内的所有数全变成0 1 a b 把[a, b]区间内的所有数全变成1 2 a b 把[ ...
- poj3667 线段树 区间合并
//Accepted 3728 KB 1079 ms //线段树 区间合并 #include <cstdio> #include <cstring> #include < ...
随机推荐
- matlab中设置colorbar为几种规定颜色
我们可以通过修改colormap的值来达到这种目的. 一般来说colormap的值是64*3的矩阵,64代表64种颜色,3列是这种颜色的RGB值,不过归一化了. 如果你想将colorbar颜色设成6种 ...
- Python3 Tkinter-Text
1.创建 from tkinter import * root=Tk() t=Text(root) t.pack() root.mainloop() 2.添加文本 from tkinter impor ...
- docker最佳实践-----美团点评的分享
美团点评容器平台简介 本文介绍美团点评的Docker容器集群管理平台(以下简称“容器平台”).该平台始于2015年,是基于美团云的基础架构和组件而开发的Docker容器集群管理平台.目前该平台为美团点 ...
- nodejs反向代理插件anyproxy安装
目前我使用的是Anyproxy,AnyProxy .这个软件的特点是可以获取到https链接的内容.在2016年年初的时候微信公众号和微信文章开始使用https链接.并且Anyproxy可以通过修改r ...
- 关于jquery几个自己不咋用到的常用遍历赛选的api
1.contains:作用是返回包含某个文字的元素节点 例子:要给所以含有“lyz”的p节点加样式: 可以这样:$("p:contains(lyz)").css("col ...
- wwnjld第二轮迭代测试报告
1.引言 1.1测试报告目的 被测试报告为wwnjld小组我们的时间管理软件的第二轮迭代所写的软件测试报告.在经过本小组大家不懈的努力之下,我们小组第二轮迭代的产品终于新鲜出炉了.这次测试小组的主要成 ...
- TCP系列12—重传—2、Linux超时重传引入示例
在前面我们概述了TCP的超时重传之后我们简单的看一下tcp超时重传的示例.首先简单的描述一下测试过程 1.设置/proc/sys/net/ipv4/tcp_early_retrans为2,关掉TLP功 ...
- PHPCMSV9 黄页新闻、产品、商机均无法浏览具体信息,显示您没有访问该信息的权限!
原帖地址:http://bbs.phpcms.cn/forum.php?mod=viewthread&tid=294956&highlight=%C3%BB%D3%D0%B7%C3%C ...
- [C/C++] C++抽象类
转自:http://www.cnblogs.com/dongsheng/p/3343939.html 一.纯虚函数定义 纯虚函数是在基类中声明的虚函数,它在基类中没有定义,但要求任何派生类都要定义自己 ...
- Luogu2540 斗地主增强版(搜索+动态规划)
单纯的暴搜似乎还是很好写的,然而过不了.出完顺子之后答案是可以dp出来的,于是大力搜然后大力dp就好了. dp时强行讨论完了几乎所有拆牌情况,理性愉悦一发. #include<iostream& ...