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. STL的基本使用之关联容器:map和multiMap的基本使用

    STL的基本使用之关联容器:map和multiMap的基本使用 简介 map 和 multimap 内部也都是使用红黑树来实现,他们存储的是键值对,并且会自动将元素的key进行排序.两者不同在于map ...

  2. 实训第二天早上--hibernate之配置文件映射和注解

    hibernate 逐步优化第一步 只按照步骤来提取的jre包导入错误第二步 继续封装,把增删改查提取出来,同时进行代码的封装HQL语句  be stranger in the code .be fo ...

  3. HTML5 Media事件

    Media 事件 由媒介(比如视频.图像和音频)触发的事件(适用于所有 HTML 元素,但常见于媒介元素中,比如 <audio>.<embed>.<img>.< ...

  4. 常用的dos命令之简略总结

    Dos常用命令  一.基础命令  1 dir  无参数:查看当前所在目录的文件和文件夹.  /s:查看当前目录已经其所有子目录的文件和文件夹.  /a:查看包括隐含文件的所有文件.  /ah:只显示出 ...

  5. 如何获取App当前版本号

    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary]; NSString *currentVersion = [infoDic ...

  6. Java循环性能随笔

    for iterator做迭代循环性能最好 然后是foreach 然后是提前声明好变量的for循环 最后是每次都要计算集合size的for       package test;   import j ...

  7. SGU 121.Bridges painting

    原题地址 题意: 新百慕大由N个岛屿组成,在岛屿之间有一些连接它们的桥.在任意两个岛屿之间,最多只有一座桥连接它们.总统先生下达命令,要求给所有桥上色. 每一座桥能被染成 白色 或者 黑色. 每一个岛 ...

  8. ubuntu 升级命令

    apt-get update && apt-get dist-upgrade

  9. Winform控件Enable=false显示优化

    在B/S开发中(ASP.NET),往往可以css样式表来让页面控件更加美观,但是在C/S中(Winform)里面,我们则需要通过其他取巧的 方式来实现.例如:当你因为某个需求需要将控件设置为Reado ...

  10. CSS3 :nth-child() 选择器

    CSS3 :nth-child() 选择器 代码: <!DOCTYPE html> <html> <head> <style> p:nth-child( ...