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. Sum All Odd Fibonacci Numbers-freecodecamp算法题目

    Sum All Odd Fibonacci Numbers 1.要求 给一个正整数num,返回小于或等于num的斐波纳契奇数之和. 斐波纳契数列中的前几个数字是 1.1.2.3.5 和 8,随后的每一 ...

  2. vue 采坑

    1.ref 在父组件中访问子组件实例,或者直接操作DOM元素时需要ref <input ref="ipt"> 通过this.$refs.ipt 得到此input $re ...

  3. ceph 性能

    mysql在以下设备备份耗时,供大家参考: 备份文件大小 sata用时 ceph用时 nas挂载sata盘用时 7G   1分钟   15G   2分钟 21分钟 47G   8分钟 82分钟 274 ...

  4. MySQL - 表中某个状态字段的状态表示区分最好用数字,如status - [9999:失败,1111:成功]

    表中某个状态字段的状态表示区分最好用数字,如status - [9999:失败,1111:成功]

  5. 【Django】URL中传递中文的问题

     开发环境:Ubuntu16.04+Django 1.11.9+Python2.7 在开发中,在做查找某些信息这个功能的时候,遇到的一个问题.需要在URL中传递查找的关键字,当关键字为中文的时候,并不 ...

  6. 精读《sqorn 源码》

    1 引言 前端精读<手写 SQL 编译器系列> 介绍了如何利用 SQL 生成语法树,而还有一些库的作用是根据语法树生成 SQL 语句. 除此之外,还有一种库,是根据编程语言生成 SQL.s ...

  7. JZOJ 3462. 【NOIP2013模拟联考5】休息(rest)

    3462. [NOIP2013模拟联考5]休息(rest) (Standard IO) Time Limits: 1000 ms  Memory Limits: 262144 KB  Detailed ...

  8. python模块之collections模块

    计数器 Counter 计数元素迭代器 elements() 计数对象拷贝 copy() 计数对象清空 clear() from collections import Counter #import ...

  9. LCS及方案数(DP)

    Description 对于一个序列

  10. IntentService和Service执行子线程对比

    1.为何要用子程序 服务是在主线程中执行的,直接在服务中执行耗时操作明显不可取,于是安卓官方增加了IntentService类来方便使用 在Service中执行子程序代码如下 @Override pu ...