HDU3308 LCIS
| Time Limit: 2000MS | Memory Limit: 32768KB | 64bit IO Format: %I64d & %I64u |
Description
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
Each case starts with two integers n , m(0<n,m<=10 5).
The next line has n integers(0<=val<=10 5).
The next m lines each has an operation:
U A B(0<=A,n , 0<=B=10 5)
OR
Q A B(0<=A<=B< n).
Output
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
Source
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1|1
using namespace std;
const int mxn=;
int n,m;
int d[mxn];
struct node{
int cnt;int lans,rans;
}t[mxn<<];
void update(int p,int l,int r,int rt){
if(l==r)return;
int mid=(l+r)>>;
if(p<=mid)update(p,ls);
else update(p,rs);
t[rt].cnt=max(t[rt<<].cnt,t[rt<<|].cnt);
t[rt].lans=t[rt<<].lans;t[rt].rans=t[rt<<|].rans;
if(d[mid]<d[mid+]){
t[rt].cnt=max(t[rt].cnt,t[rt<<].rans+t[rt<<|].lans);
if(t[rt<<].lans==mid-l+)
t[rt].lans=t[rt<<].lans+t[rt<<|].lans;
if(t[rt<<|].rans==r-mid)
t[rt].rans=t[rt<<|].rans+t[rt<<].rans;
}
return;
}
void Build(int l,int r,int rt){
if(l==r){
t[rt].cnt=t[rt].lans=t[rt].rans=;
return;
}
int mid=(l+r)>>;
Build(ls);
Build(rs);
t[rt].cnt=max(t[rt<<].cnt,t[rt<<|].cnt);
t[rt].lans=t[rt<<].lans;
t[rt].rans=t[rt<<|].rans;
if(d[mid]<d[mid+]){
t[rt].cnt=max(t[rt].cnt,t[rt<<].rans+t[rt<<|].lans);
if(t[rt<<].lans==mid-l+)
t[rt].lans=t[rt<<].lans+t[rt<<|].lans;
if(t[rt<<|].rans==r-mid)
t[rt].rans=t[rt<<|].rans+t[rt<<].rans;
}
return;
}
int query(int L,int R,int l,int r,int rt){
if(L<=l && r<=R) return t[rt].cnt;
int mid=(l+r)>>;
if(R<=mid)return query(L,R,ls);
if(mid<L)return query(L,R,rs);
else{
int res=max(query(L,R,ls),query(L,R,rs));
if(d[mid]<d[mid+]){//如果结点所存答案长于区间长度,实际答案等于区间长度,用min维护
res=max(res,(min(t[rt<<].rans,mid-L+)+min(t[rt<<|].lans,R-mid)));
}
return res;
}
}
int main(){
int T;
scanf("%d",&T);
while(T--){
memset(t,,sizeof );
int i,j;
scanf("%d%d",&n,&m);
for(i=;i<=n;i++)scanf("%d",&d[i]);
Build(,n,);
char op[];int a,b;
for(i=;i<=m;i++){
scanf("%s%d%d",op,&a,&b);
if(op[]=='U'){
d[++a]=b;
update(a,,n,);
}
if(op[]=='Q'){ printf("%d\n",query(a+,b+,,n,));
}
}
}
return ;
}
HDU3308 LCIS的更多相关文章
- hdu-3308 LCIS (线段树区间合并)
LCIS Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU-3308 LCIS(区间合并)
题目大意:给一个整数序列,m次询问,每次询问某个区间中最长连续上升子序列的长度. 题目分析:线段树区间合并.维护以区间左端开头的.以区间右端点结尾的和区间最长的上升连续序列. 代码如下: # incl ...
- HDU3308(LCIS) 线段树好题
题目链接:传送门 题目大意:给你n个数,m个操作.操作有两种:1.U x y 将数组第x位变为y 2. Q x y 问数组第x位到第y位连续最长子序列的长度.对于每次询问,输出一个答案 题目思路: ...
- 线段树总结 (转载 里面有扫描线类 还有NotOnlySuccess线段树大神的地址)
转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnl ...
- [转载]完全版线段树 by notonlysuccess大牛
原文出处:http://www.notonlysuccess.com/ (好像现在这个博客已经挂掉了,在网上找到的全部都是转载) 今天在清北学堂听课,听到了一些很令人吃惊的消息.至于这消息具体是啥,等 ...
- 【转】线段树完全版~by NotOnlySuccess
线段树完全版 ~by NotOnlySuccess 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文章了,觉 ...
- 《完全版线段树》——notonlysuccess
转载自:NotOnlySuccess的博客 [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文 ...
- 【转】 线段树完全版 ~by NotOnlySuccess
载自:NotOnlySuccess的博客 [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文章 ...
- 【转载】完全版线段树 by notonlysuccess大牛
原文出处:http://www.notonlysuccess.com/ 今晚上比赛就考到了 排兵布阵啊,难受. [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时 ...
随机推荐
- vue学习之路 - 1.初步感知
一.安装 这里使用node的npm包管理工具进行操作.操作前请先下载node. 在工程文件夹中使用以下命令安装vue: npm install vue 如下图所示:我在 helloworld 文件夹中 ...
- JS学习笔记-构造函数篇
创建实例 funtion Fn (){ var num = 10; this.x = 100; this.getX = function(){ cons ...
- ASP.NET Core模块化前后端分离快速开发框架介绍之3、数据访问模块介绍
源码 GitHub:https://github.com/iamoldli/NetModular 演示地址 地址:https://nm.iamoldli.com 账户:admin 密码:admin 前 ...
- PHP实现的敏感词过滤方法
PHP实现的敏感词过滤方法,以下是一份过滤敏感词的编码.有需要可以参考参考. /** * @todo 敏感词过滤,返回结果 * @param array $list 定义敏感词一维数组 * @para ...
- JZOJ 5838. 旅游路线 最大子段和
5838. 旅游路线 Time Limits: 1000 ms Memory Limits: 131072 KB Detailed Limits Goto ProblemSet Descrip ...
- 数据结构-哈夫曼(Huffman)
#include <iostream> #include <cstdio> #include <malloc.h> #define LIST_INIT_SIZE 1 ...
- Tomcat 在 Linux 下的自动启动脚本
很多服务都需要设置为开机自启动.将下面代码复制到 /etc/rc.d/init.d/tomcat ,然后执行 chkconfig –add tomcat chkconfig tomcat on 就可以 ...
- Intellij Idea 创建JavaWeb项目
折腾Tomcat折腾了两个晚上,第一个晚上怎么都进不了Tomcat的首页,第二个晚上进去了,但是新建的Web项目,在浏览器中运行,总是 Error on Apache Tomcat: The requ ...
- Java-数据结构之栈练习
栈(stack)可以看做是特殊类型的线性表,访问.插入和删除其中的元素只能在栈尾(栈顶)进行. 队列(queue)表示一个等待的线性表,它也可以看做是一种特殊类型的线性表,元素只能从队列的末端(队列尾 ...
- Nodejs-文件流
1.什么是流? 流是程序输入输出的一个连续的字节序列. 有文件流,网络流,设备(例如鼠标,键盘,磁盘,调制解调器和打印机)的输入输出都是用流来处理的. 任何数据的最根本表现形式都是二进制. 读取文件 ...