线段树(区间维护):HDU 3308 LCIS
LCIS
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5951 Accepted Submission(s): 2578
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].
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).
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
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的更多相关文章
- 线段树(区间合并) HDOJ 3308 LCIS
题目传送门 题意:线段树操作:1. 单点更新 2. 求区间的LCIS(longest consecutive increasing subsequence) 分析:注意是连续的子序列,就是简单的区间合 ...
- hdu 1556 Color the ball(线段树区间维护+单点求值)
传送门:Color the ball Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/3276 ...
- HDU 6315 Naive Operations(线段树+区间维护)多校题解
题意:a数组初始全为0,b数组题目给你,有两种操作: 思路:dls的思路很妙啊,我们可以将a初始化为b,加一操作改为减一,然后我们维护一个最小值,一旦最小值为0,说明至少有一个ai > bi,那 ...
- 线段树 + 区间更新 ----- HDU 4902 : Nice boat
Nice boat Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tot ...
- POJ3468(线段树区间维护)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 85502 ...
- HDU1540 Tunnel Warfare(线段树区间维护&求最长连续区间)题解
Tunnel Warfare Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- 线段树-区间更新-HDU 1689
#include <iostream> #include <cstdio> #include <string> #include <cstring> # ...
- hdu 5475 An easy problem(暴力 || 线段树区间单点更新)
http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...
- LCIS HDU - 3308 (线段树区间合并)
LCIS HDU - 3308 Given n integers. You have two operations: U A B: replace the Ath number by B. (inde ...
随机推荐
- Oracle 卸载 不干净
关闭oracle相关的服务 注册表删除(可能因为oracle及windows的版本不同注册表信息也有些差异): 开始è输入regedit 打开注册表编辑器删除下面的目录 HKEY_LOCAL_MACH ...
- js时间字符串转Date对象
var DATE_REGEXP = new RegExp("(\\d{4})-(\\d{2})-(\\d{2})([T\\s](\\d{2}):(\\d{2}):(\\d{2})(\\.(\ ...
- 什么是php命名空间
php命名空间是在5.3版本后加入的,命名空间反过来就是空间命名,在这里的空间命名就像window下的文件夹命名,命名空间用关键字namespace来定义.在这里用文件夹举三个例子,比如相对于test ...
- HTML5 FileReader读取Blob对象API详解
使用FileReader对象,web应用程序可以异步的读取存储在用户计算机上的文件(或者原始数据缓冲)内容,可以使用File对象或者Blob对象来指定所要读取的文件或数据.其中File对象可以是来自用 ...
- SQL替换空格,制表符,换行符,回车符.
首先是空格的替换,很重要的有点是,要确保字段的类型,不是char或nchar等固定的类型,否则无法去掉空格. 去掉空格很简单,如下为SQL实例: --去掉 T_StuffBasic 表中FBranch ...
- For and While loop choice.
/* Difference between 'for' and 'while'. We can transform everything between 'for' and 'while'. if t ...
- windows下eclipse+hadoop2
windows下eclipse+hadoop2.4开发手册 1.解压下载的hadoop2.4,到任意盘符,例如D:\hadoop-2.4.0. 2.设置环境变量 ①新建系统变量,如下所示. ②将新建的 ...
- How to Make LastPass Even More Secure with Google Authenticator
Google Authenticator LastPass supports Google Authenticator, which is officially available as an app ...
- 用java写bp神经网络(二)
接上篇. Net和Propagation具备后,我们就可以训练了.训练师要做的事情就是,怎么把一大批样本分成小批训练,然后把小批的结果合并成完整的结果(批量/增量):什么时候调用学习师根据训练的结果进 ...
- spring-quartz普通任务与可传参任务
两者区别与作用: 普通任务:总调度(SchedulerFactoryBean)--> 定时调度器(CronTriggerFactoryBean) --> 调度明细自定义执行方法bean(M ...