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. 什么是html,什么是php

    学了这么长时间的网站建设,好像对这两个概念说以来还是语无伦次的,所以就来写一写了.html是什么呢,官方解释:超文本标记语言,超文本就是指页面可以包含图片,连接等非文字元素.超文本标记语言也是一种规范 ...

  2. jni使用

    版权声明:本文为博主原创文章,未经博主允许不得转载.   目录(?)[-] 简介 详解 JNI 元素 JNI函数实战 AndroidmkApplicationmk Androidmk Applicat ...

  3. 可以打开mdb文件的小软件

    下载地址: http://dl-sh-ocn-1.pchome.net/09/rh/DatabaseBrowser.zip

  4. oracle行列转换总结-转载自ITPUB

    原贴地址:http://www.itpub.net/thread-1017026-1-1.html 谢谢原贴大人 最近论坛很多人提的问题都与行列转换有关系,所以我对行列转换的相关知识做了一个总结, 希 ...

  5. iOS CGContextRef 画图小结

    CGContextRef context = UIGraphicsGetCurrentContext(); //设置上下文 //画一条线 CGContextSetStrokeColorWithColo ...

  6. Java中char占用几个字节

    在讨论这个问题之前,我们需要先区分unicode和UTF. unicode :统一的字符编号,仅仅提供字符与编号间映射.符号数量在不断增加,已超百万.详细:[https://zh.wikipedia. ...

  7. 【vc】14_网络编程_socket编程

    1.计算机网络基本知识 最简单的网络程序如图: 提示:IP地址就相当于一个公司的总机号码,端口号就相当于分机号码.在打电话时,拨通总机后,还需要转到分机上. (1)协议 ·为进行网络中的数据交换(通信 ...

  8. 初试ubuntu14.4问题集锦

    接触Linux系统也好长时间了,但每次都是浅尝则止.前几天突发兴趣,想认真地学习一下这个名扬天下的稳定的操作系统.于是试着装了一下炒作的最凶的Ubuntu. 安装的Ubuntu系统版本为14.04. ...

  9. 动态树LCT小结

    最开始看动态树不知道找了多少资料,总感觉不能完全理解.但其实理解了就是那么一回事...动态树在某种意思上来说跟树链剖分很相似,都是为了解决序列问题,树链剖分由于树的形态是不变的,所以可以通过预处理节点 ...

  10. 知识库系统confluence5.8.10 安装与破解

    一直对知识库体系很在意,设想这样的场景,公司历年的研发资料只要一个搜索,相关的知识点就全部摆在面前,任君取用,想一想就无限迷人,只是从10年开始,由于种种原因,终究没能好好研究一下.最近机缘巧合,可以 ...