LCIS

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
 
题意:求区间[a,b]连续上升的最大区间长度。
解析:线段树维护以下几种信息:左右端点(le,ri),区间长度(len),左端的数(lenum),右端的数(rinum),从左边开始的最大连续上升子序列的长度(lelis),从右边开始的最大上升子序列的长度(rilis),该区间的最大连续上升子序列的长度(maxlen).具体操作见代码。
代码如下:
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<iterator>
#include<utility>
#include<sstream>
#include<iostream>
#include<cmath>
#include<stack>
using namespace std;
const int INF=;
const double eps=0.00000001;
const int maxn=;
struct node
{
int le,ri,len;
int lenum,rinum;
int maxlis,lelis,rilis;
}tree[*maxn];
int elem[maxn];
void pushup(int id)
{
node& fa=tree[id]; //父亲
node& lson=tree[id*]; // 左儿子
node& rson=tree[id*+]; //右儿子
fa.lelis=lson.lelis, fa.rilis=rson.rilis; //更新
fa.lenum=lson.lenum, fa.rinum=rson.rinum;
fa.maxlis=max(lson.maxlis,rson.maxlis); //左右儿子中的最大值
if(lson.rinum<rson.lenum) //如果中间可以形成上升的连续的一段
{
if(lson.lelis==lson.len) fa.lelis+=rson.lelis; //可扩展
if(rson.rilis==rson.len) fa.rilis+=lson.rilis;
fa.maxlis=max(fa.maxlis,lson.rilis+rson.lelis); //最大值更新
}
}
void build_tree(int le,int ri,int id)
{
node& t=tree[id];
t.le=le,t.ri=ri,t.len=ri-le+;
if(le==ri)
{
t.lenum=t.rinum=elem[le];
t.maxlis=t.lelis=t.rilis=;
return;
}
int mid=(le+ri)/;
build_tree(le,mid,id*);
build_tree(mid+,ri,id*+);
pushup(id);
}
int query(int x,int y,int id)
{
if(tree[id].le>=x&&tree[id].ri<=y)
{
return tree[id].maxlis;
}
int mid=(tree[id].le+tree[id].ri)/;
int ret=;
if(x<=mid) ret=max(ret,query(x,y,id*)); //左边
if(y>mid) ret=max(ret,query(x,y,id*+));// 右边
if(tree[id*].rinum<tree[id*+].lenum) ret=max(ret,min(mid-x+,tree[id*].rilis)+min(y-mid,tree[id*+].lelis));//中间
return ret;
}
void update(int id,int pos,int val)
{
if(tree[id].le==tree[id].ri)
{ tree[id].lenum=tree[id].rinum=val; //单点更新
return;
}
int mid=(tree[id].le+tree[id].ri)/;
if(pos<=mid) update(id*,pos,val);
else update(id*+,pos,val);
pushup(id);
}
int main()
{
int T;
cin>>T;
while(T--)
{
int N,M;
cin>>N>>M;
for(int i=;i<=N;i++) scanf("%d",&elem[i]);
build_tree(,N,);
while(M--)
{
char S[];
int from,to;
scanf("%s%d%d",S,&from,&to);
if(S[]=='Q') printf("%d\n",query(from+,to+,));
else update(,from+,to);
}
}
return ;
}
 

HDU 3308 LCIS(线段树单点更新区间合并)的更多相关文章

  1. POJ 2892 Tunnel Warfare(线段树单点更新区间合并)

    Tunnel Warfare Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 7876   Accepted: 3259 D ...

  2. hdu1540之线段树单点更新+区间合并

    Tunnel Warfare Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  3. hdu 5316 Magician(2015多校第三场第1题)线段树单点更新+区间合并

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5316 题意:给你n个点,m个操作,每次操作有3个整数t,a,b,t表示操作类型,当t=1时讲a点的值改 ...

  4. HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)

    HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...

  5. hdu 1166线段树 单点更新 区间求和

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  6. POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)

    POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...

  7. POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化)

    POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化) 题意分析 前置技能 线段树求逆序对 离散化 线段树求逆序对已经说过了,具体方法请看这里 离散化 有些数 ...

  8. hdu1166(线段树单点更新&区间求和模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166 题意:中文题诶- 思路:线段树单点更新,区间求和模板 代码: #include <iost ...

  9. hdu 2795 Billboard 线段树单点更新

    Billboard Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=279 ...

随机推荐

  1. Linux服务器SNMP常用OID (转)

    原文地址:http://www.haiyun.me/archives/linux-snmp-oid.html 收集整理一些Linux下snmp常用的OID,用做服务器监控很不错. 服务器负载: 1 2 ...

  2. qcow2 raw vhd 虚拟磁盘转换

    Centos-6.4-x86_64_Ruiy.vhd: Microsoft Disk Image, Virtual Server or Virtual PC

  3. 【转】基于Qt, TUIO和TSLIB的嵌入式Linux下的多点触摸设计

    这个教程描述了在嵌入式linux下使用Qt如何设置一个支持多点触摸和单点触摸的输入系统.这里假定你已经有了对应的驱动程序,驱动可以从触摸屏的厂商那里获得或者使用一个linux 内核源码中已经存在的驱动 ...

  4. python3-day1(基础总结)

    总结比较抽象的难点: 1.二进制运算 60 & 13  =12 60 |  13  =61 60 ^ 13  =49 60<<2   =240 60>>2   =15 ...

  5. C# 使用枚举获取对应的数组值时

    using System; enum Move { walk, run } class Program { static float[] speedAry = { 50.0f, 200.0f }; p ...

  6. HDU 1827 Summer Holiday(Tarjan缩点)

    Problem Description To see a World in a Grain of Sand  And a Heaven in a Wild Flower,  Hold Infinity ...

  7. [Spring入门学习笔记][静态资源]

    遗留问题 在上一节课的作业中,我们一定遇到了一点问题——虽然将页面内容正确的返回给了浏览器,但是浏览器显示的样式却是不正确的,这是因为在HTML的\标签中我们这样引入了CSS资源: <link ...

  8. Linux命令:FREE

    FREE(1)                       Linux User's Manual                      FREE(1) NAME free - Display a ...

  9. 解决MySQL中文乱码的问题

    遇到中文乱码问题,首先用status命令检查数据库的配置,如下: 上图会显示数据库配置的各项信息. 还可以用 show create database XXX,来显示创建数据库的时候的编码设置. 一般 ...

  10. 【solr专题之三】Solr常见异常

    1.RemoteSolrException: Expected mime type application/octet-stream but got text/html 现象: SLF4J: Fail ...