LCIS

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5951    Accepted Submission(s): 2578

Problem 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<=105).
The next line has n integers(0<=val<=105).
The next m lines each has an operation:
U A B(0<=A,n , 0<=B=105)
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
 #include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn=;
int T[maxn<<],L[maxn<<],R[maxn<<],ar[maxn],n,m; void Updata(int node,int l,int r)
{
int mid=(l+r)>>,a=node<<,b=a|; L[node]=L[a];
if(L[a]==mid-l+&&ar[mid]<ar[mid+])
L[node]+=L[b]; R[node]=R[b];
if(R[b]==r-mid&&ar[mid]<ar[mid+])
R[node]+=R[a]; T[node]=max(T[a],T[b]);
if(ar[mid]<ar[mid+])
T[node]=max(T[node],R[a]+L[b]);
} void Change(int node,int l,int r,int pos,int x)
{
if(l==r){
T[node]=L[node]=R[node]=;
ar[pos]=x;
return;
}
int mid=(l+r)>>;
if(mid>=pos)
Change(node<<,l,mid,pos,x);
else
Change(node<<|,mid+,r,pos,x);
Updata(node,l,r);
}
int ans; int Query(int node,int l,int r,int a,int b)
{
if(l>=a&&r<=b)
return T[node];
int mid=(l+r)>>;
int ret=;
if(a<=mid)
ret=Query(node<<,l,mid,a,b);
if(b>mid)
ret=max(ret,Query(node<<|,mid+,r,a,b));
if(a<=mid&&b>mid&&ar[mid]<ar[mid+])
ret=max(ret,min(R[node<<],mid-a+)+min(L[node<<|],b-mid));
return ret;
}
int main()
{
int Tk,a,b;
char s[];
scanf("%d",&Tk);
while(Tk--)
{
scanf("%d%d",&n,&m);
memset(L,,sizeof(L));
memset(R,,sizeof(R));
memset(T,,sizeof(T)); for(int i=;i<=n;i++){
scanf("%d",&ar[i]);
Change(,,n,i,ar[i]);
}
while(m--){
scanf("%s",s);
scanf("%d%d",&a,&b);
if(s[]=='U')
Change(,,n,a+,b);
else{
printf("%d\n",Query(,,n,a+,b+));
}
}
}
return ;
}

线段树(区间维护):HDU 3308 LCIS的更多相关文章

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

    题目传送门 题意:线段树操作:1. 单点更新 2. 求区间的LCIS(longest consecutive increasing subsequence) 分析:注意是连续的子序列,就是简单的区间合 ...

  2. hdu 1556 Color the ball(线段树区间维护+单点求值)

    传送门:Color the ball Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/3276 ...

  3. HDU 6315 Naive Operations(线段树+区间维护)多校题解

    题意:a数组初始全为0,b数组题目给你,有两种操作: 思路:dls的思路很妙啊,我们可以将a初始化为b,加一操作改为减一,然后我们维护一个最小值,一旦最小值为0,说明至少有一个ai > bi,那 ...

  4. 线段树 + 区间更新 ----- HDU 4902 : Nice boat

    Nice boat Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  5. POJ3468(线段树区间维护)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 85502   ...

  6. HDU1540 Tunnel Warfare(线段树区间维护&求最长连续区间)题解

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

  7. 线段树-区间更新-HDU 1689

    #include <iostream> #include <cstdio> #include <string> #include <cstring> # ...

  8. hdu 5475 An easy problem(暴力 || 线段树区间单点更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...

  9. LCIS HDU - 3308 (线段树区间合并)

    LCIS HDU - 3308 Given n integers. You have two operations: U A B: replace the Ath number by B. (inde ...

随机推荐

  1. js 高阶函数 filter

    filter用于过滤array中的一些值,通过带入的函数返回的ture 或false 保留或去除,返回一个新的array filter 使用演示:判断筛选出array中的素数: //判断素数自定义函数 ...

  2. Rouh set 入门知识2(基础定义篇)

    接上一篇,简单说明一下知识库的关系,设K1=(U,S1)和K2=(U,S2)为知识库 1.如果IND(S1)=IND(S2),即U/IND(S1)=U/IND(S2),则知识库K1与知识库K2是等价的 ...

  3. $(this).next()与$(this).children()

    $(this).next() 当前元素同级的下个元素,而非子元素 $(this).children() 是当前元素的下一级元素的集合,就是子元素的集合,而不管子元素的后代元素 所以这两个没有什么可比性 ...

  4. switch语法之PHP

    $a = 100; switch ($a) { case 100: echo '满分'; break; case $a >=60: echo '及格'; break; }

  5. Nginx和Apache共存环境下apache获得真实IP

    自从Nginx出现以后,我们都喜欢让 Nginx 跑在前方处理静态文件,然后通过 proxy 把动态请求过滤给 apache.这么有个问题,跑在后方 apache 上的应用获取到的IP都是Nginx所 ...

  6. 设置 textField.placeholder的颜色和大小

    textField.placeholder = @"请输入手机号码"; [textField setValue:[UIColor blue] forKeyPath:@"_ ...

  7. iOS将产品进行多语言发布,开发

    多语言就是程序的国际化.在Xcode中要实现程序的国际化,只需要简单配置,并修改相应的字符串键值对即可. 应用程序的国际化主要包括三个方面:A.程序名称国际化:B.程序内容国际化:C.程序资源国际化 ...

  8. STL库list::sort()实现深度解析

    原创,转载请注明出处:STL库list::sort()实现深度解析 list模板的定义以及一些基本成员函数的实现这里我就不赘述了,还不清楚的同学可以到网上查找相关资料或者直接查看侯捷翻译的<ST ...

  9. ZOJ 刷题记录 (。・ω・)ノ゙(Progress:31/50)

    [热烈庆祝ZOJ回归] P1002:简单的DFS #include <cstdio> #include <cstring> #include <algorithm> ...

  10. Spring 整合Redis 出现 afterPropertiesSet signature: ()V) Incompatible argument to function 解决办法

    正在做SpringMVC+Redis整合的练习 使用的是 spring-data-redis 和 Jedis 配置好之后出现了以下错误: Caused by: java.lang.VerifyErro ...