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. python笔记-list列表的方法

    #!usr/bin/python # -*- coding: utf-8 -*- # 存储5个人的年龄,求他们的平均年龄 age1 = 18 age2 = 15 age3 = 38 age4 = 20 ...

  2. SQL Server中的日期,时间组合查询

    如图所示,Jdate和Jdate2是两个分开的字段,一个是date类型,存储日期,一个是time(0)类型,存储具体时间 现在有这样的要求,就是获得(Jdate和Jdate2组合起来的日期时间)在(当 ...

  3. 使用U盘给笔记本重做系统

    **一.戴尔 Vostro 14 3000 Series **1. 开机时快速按F12进入BIOS界面 **2. 按照下图进行一系列的处理,把U盘被设置为第一启动项 **3. 插入U盘后进入老毛桃PE ...

  4. python读取xls文件

    #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/10/17 14:41 # @Author : Sa.Song # @Desc ...

  5. HDU5952 Counting Cliques 暴搜优化

    一.前言 这题看上去相当唬人(NPC问题),但是 因为限制了一些条件,所以实际上并没有太唬人. 二.题目 给你一个图,要求你找出数量为S的团的数量. 三.题解 暴搜,再加上一些玄学优化. 优化1:使用 ...

  6. Diycode开源项目 MyTopicActivity分析

    1.总体浏览效果及布局分析 1.1.看一下我的帖子预览效果 1.2.然后看一下我的收藏预览效果 1.3.归纳一下 所以我的帖子和我的收藏可以共用同一个类. 布局效果几乎一样,只是用户的选择不同. 所以 ...

  7. android json 解析 kotlin

    前面 写了一次 kotlin解析json 但是,真的写得太烂,直接删掉了,现在重新整理一下.顺便记录一下今天坑了我很久的小问题. 1.首先从最简单的入手吧 一个json的字符串:=====就叫做jso ...

  8. Kali 远程登陆SSH

    一.配置SSH 编辑/etc/ssh/sshd_config 将#PasswordAuthentication no的注释去掉,将NO修改为YES //可以用密码登陆 将PermitRootLogin ...

  9. vba中ListBox控件的使用

    给ListBox添加内容 If CheckBox8 = True Then---------------------------checkbox控件被选中 For i = 0 To ListBox1. ...

  10. 8 django 里面的API

    1.什么是API? 2.在djang里面写API 3.API实战效果 1.移动端的网页 4.restframework :老师方法 (0)安装 Django REST framework 是一个强大且 ...