Time Limit: 2000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u

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<=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

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

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的更多相关文章

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

    LCIS Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

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

    题目大意:给一个整数序列,m次询问,每次询问某个区间中最长连续上升子序列的长度. 题目分析:线段树区间合并.维护以区间左端开头的.以区间右端点结尾的和区间最长的上升连续序列. 代码如下: # incl ...

  3. HDU3308(LCIS) 线段树好题

    题目链接:传送门 题目大意:给你n个数,m个操作.操作有两种:1.U x y 将数组第x位变为y   2. Q x y 问数组第x位到第y位连续最长子序列的长度.对于每次询问,输出一个答案 题目思路: ...

  4. 线段树总结 (转载 里面有扫描线类 还有NotOnlySuccess线段树大神的地址)

    转载自:http://blog.csdn.net/shiqi_614/article/details/8228102 之前做了些线段树相关的题目,开学一段时间后,想着把它整理下,完成了大牛NotOnl ...

  5. [转载]完全版线段树 by notonlysuccess大牛

    原文出处:http://www.notonlysuccess.com/ (好像现在这个博客已经挂掉了,在网上找到的全部都是转载) 今天在清北学堂听课,听到了一些很令人吃惊的消息.至于这消息具体是啥,等 ...

  6. 【转】线段树完全版~by NotOnlySuccess

    线段树完全版  ~by NotOnlySuccess 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文章了,觉 ...

  7. 《完全版线段树》——notonlysuccess

    转载自:NotOnlySuccess的博客 [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文 ...

  8. 【转】 线段树完全版 ~by NotOnlySuccess

    载自:NotOnlySuccess的博客 [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时觉得挺自豪的,还去pku打广告,但是现在我自己都不太好意思去看那篇文章 ...

  9. 【转载】完全版线段树 by notonlysuccess大牛

    原文出处:http://www.notonlysuccess.com/ 今晚上比赛就考到了 排兵布阵啊,难受. [完全版]线段树 很早前写的那篇线段树专辑至今一直是本博客阅读点击量最大的一片文章,当时 ...

随机推荐

  1. Webpack--模块打包器

    首先介绍一个安装webpack的百度经验:https://jingyan.baidu.com/article/a3a3f811230ee58da3eb8a6e.html 推荐一个详细介绍webpack ...

  2. BZOJ1576: [Usaco2009 Jan]安全路经Travel(最短路 并查集)

    题意 给你一张无向图,保证从1号点到每个点的最短路唯一.对于每个点求出删掉号点到它的最短路上的最后一条边(就是这条路径上与他自己相连的那条边)后1号点到它的最短路的长度 Sol emmm,考场上想了个 ...

  3. 爬虫学习(五)——使用handler管理器对象进行数据爬取的步骤

    # 使用管理器对象进行爬取数据的步骤 import urllib.requesturl = "https://www.baidu.com/"# 创建handler的管理器对象han ...

  4. celery:Unrecoverable error: AttributeError("'unicode' object has no attribute 'iteritems')

    环境描述 python2+django1.9下使用celery异步处理耗时请求. celery使用的是celery-with-redis这个第三方库,版本号为3.0. pip install cele ...

  5. 老男孩Python全栈第2期+课件笔记【高清完整92天整套视频教程】

    点击了解更多Python课程>>> 老男孩Python全栈第2期+课件笔记[高清完整92天整套视频教程] 课程目录 ├─day01-python 全栈开发-基础篇 │ 01 pyth ...

  6. javascript 计算倒计时

    function timeDown(second) { var month = '', day = '', hour = '', minute = ''; if (second >= 86400 ...

  7. JZOJ 5835 Prime

    Description

  8. Union found

    Use array. class UnionFound { public: vector<int> v; int cnt; UnionFound(int n) { v = vector&l ...

  9. BZOJ 4247: 挂饰

    背包裸题 #include<cstdio> #include<algorithm> using namespace std; int F[2005]; struct node{ ...

  10. 数据结构之B-树

    作为文件系统索引的常用数据结构,B-树的查找涉及硬盘和内存两个部分,硬盘的读写将影响查找的速度.传统关系型数据库如Mysql采用B-树作为索引,新型内存数据库levledb通过改进数据组织方式通过内存 ...