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. alpha属性设置

    alpha是来设置透明度的,它的基本属性是filter:alpha(opacity,finishopacity,style,startX,startY,finishX,finishY).opacity ...

  2. Adb connect监听指定的主机和端口/Adb监听Visual Studio Emulator for Android模拟器

    语法: adb connect <host>[:<port>] 使用实例: adb connect //如果连接成功则返回 connected to 说明 在使用Visual ...

  3. c-八进制 转 十进制

    概述 其实x进制转十进制的算法都差不多,不过如果是针对于字符形式,他们却有点不同.使用指针和数组的形式计算,又不同.这里演示将字符型的数组形式的八进制转成十进制: #include <stdio ...

  4. How to Make LastPass Even More Secure with Google Authenticator

    Google Authenticator LastPass supports Google Authenticator, which is officially available as an app ...

  5. Scanner中next()和nextline()读取字符串方法和区别

    在实现字符窗口的输入时,我个人更喜欢选择使用扫描器Scanner,它操作起来比较简单.在写作业的过程中,我发现用Scanner实现字符串的输入有两种方法,一种是next(),一种nextLine(), ...

  6. angular.js 字符串

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script sr ...

  7. VS 编程常见错误及解决方法

    1. VS2013 无法打开包括文件:“cv.h"等一些头文件 解决方法: cv.h是build\include文件夹下的头文件,所在文件夹位置是D:\Program Files (x86) ...

  8. Mvvm绑定datagrid或listview的selectItems的方法[转]

    单选,很简单,将SelectedItem与ViewModel的属性进行双向绑定就OK了 多选,由于ListView的SelectedItems不能进行绑定,需要将ListView的SelectionC ...

  9. 生成四位随机数的PHP代码

    纯数字的四位随机数 rand(1000,9999) 数字和字符混搭的四位随机字符串: function GetRandStr($len) { $chars = array( "a" ...

  10. html5 DeviceOrientation来实现手机网站上的摇一摇功能

    原文地址:http://www.cootm.com/?p=706 从网上转载看到的,感觉不错,就转过来了,特此感谢 cnblogs 的 幸福2胖纸的码农生活,直接转载了,不要介意!呵呵 以下是转载内容 ...