LCIS

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 5319    Accepted Submission(s): 2361

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
 
Author
shǎ崽
 
Source
 
Recommend
wxl   |   We have carefully selected several similar problems for you:  3397 

pid=1542" target="_blank" style="color:rgb(26,92,200); text-decoration:none">1542 1828 2871 1255 


ac代码
#include<stdio.h>
#include<string.h>
#define max(a,b) (a>b? a:b)
#define min(a,b) (a>b? b:a)
struct s
{
int lnum,rnum;
int lmax,rmax,mmax;
}node[1000100<<2];
void init(int tr,int num)
{
node[tr].lnum=num;
node[tr].rnum=num;
node[tr].lmax=1;
node[tr].rmax=1;
node[tr].mmax=1;
}
void pushup(int tr,int m)
{
node[tr].lnum=node[tr<<1].lnum;
node[tr].rnum=node[tr<<1|1].rnum;
node[tr].lmax=node[tr<<1].lmax;
node[tr].rmax=node[tr<<1|1].rmax;
node[tr].mmax=max(node[tr<<1].mmax,node[tr<<1|1].mmax);
if(node[tr<<1].rnum<node[tr<<1|1].lnum)
{
node[tr].mmax=max(node[tr].mmax,node[tr<<1].rmax+node[tr<<1|1].lmax);
if(node[tr<<1].lmax==m-(m>>1))
node[tr].lmax+=node[tr<<1|1].lmax;
if(node[tr<<1|1].rmax==(m>>1))
node[tr].rmax+=node[tr<<1].rmax;
}
}
void build(int l,int r,int tr)
{
if(l==r)
{
int num;
scanf("%d",&num);
init(tr,num);
return;
}
int mid=(l+r)>>1;
build(l,mid,tr<<1);
build(mid+1,r,tr<<1|1);
pushup(tr,r-l+1);
}
void update(int pos,int num,int l,int r,int tr)
{
if(l==r)
{
init(tr,num);
return;
}
int mid=(l+r)>>1;
if(pos<=mid)
{
update(pos,num,l,mid,tr<<1);
}
else
update(pos,num,mid+1,r,tr<<1|1);
pushup(tr,r-l+1);
}
int query(int L,int R,int l,int r,int tr)
{
if(L<=l&&R>=r)
{
return node[tr].mmax;
}
int mid=(l+r)>>1;
int temp1=0,temp2=0,temp3=0;
if(L<=mid)
temp1=query(L,R,l,mid,tr<<1);
if(R>mid)
temp2=query(L,R,mid+1,r,tr<<1|1);
if(L<=mid&&R>mid&&node[tr<<1].rnum<node[tr<<1|1].lnum)
temp3=min(mid-L+1,node[tr<<1].rmax)+min(R-mid,node[tr<<1|1].lmax);
int ans=max(temp1,max(temp2,temp3));
return ans;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d%d",&n,&m);
build(1,n,1);
while(m--)
{
char s[2];
int a,b;
scanf("%s%d%d",s,&a,&b);
if(s[0]=='U')
{
update(a+1,b,1,n,1);
}
else
{
printf("%d\n",query(a+1,b+1,1,n,1));
}
}
}
}

HDOJ 题目3308 LCIS(线段树,区间查询,区间合并)的更多相关文章

  1. 线段树的区间合并 B - LCIS

    B - LCIS HDU - 3308 这个是一个很简单很明显的线段树的区间合并,不过区间合并的题目都还是有点难写,建议存个板子. #include <cstdio> #include & ...

  2. 线段树:CDOJ1592-An easy problem B (线段树的区间合并)

    An easy problem B Time Limit: 2000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Pr ...

  3. Codeforces Round #222 (Div. 1) D. Developing Game 线段树有效区间合并

    D. Developing Game   Pavel is going to make a game of his dream. However, he knows that he can't mak ...

  4. CodeForces - 587E[线段树+线性基+差分] ->(线段树维护区间合并线性基)

    题意:给你一个数组,有两种操作,一种区间xor一个值,一个是查询区间xor的结果的种类数 做法一:对于一个给定的区间,我们可以通过求解线性基的方式求出结果的种类数,而现在只不过将其放在线树上维护区间线 ...

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

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 题目很好懂,就是单点更新,然后求区间的最长上升子序列. 线段树区间合并问题,注意合并的条件是a[ ...

  6. HDU 3308 LCIS 线段树区间更新

    最近开始线段树一段时间了,也发现了不少大牛的博客比如HH大牛  ,小媛姐.这个题目是我在看HH大牛的线段树专题是给出的习题,(可以去他博客找找,真心推荐)原本例题是POJ3667 Hotel 这个题目 ...

  7. HDU 3308 LCIS(线段树单点更新区间合并)

    LCIS Given n integers. You have two operations: U A B: replace the Ath number by B. (index counting ...

  8. HDU 3308 LCIS (线段树&#183;单点更新&#183;区间合并)

    题意  给你一个数组  有更新值和查询两种操作  对于每次查询  输出相应区间的最长连续递增子序列的长度 基础的线段树区间合并  线段树维护三个值  相应区间的LCIS长度(lcis)  相应区间以左 ...

  9. hud 3308 LCIS 线段树 区间合并

    题意: Q a b 查询[a, b]区间的最长连续递增子序列的长度 U a b 将下表为a的元素更新为b 区间合并一般都有3个数组:区间最值,左区间最值和右区间最值 具体详见代码 #include & ...

  10. POJ 3667 & HDU 3308 & HDU 3397 线段树的区间合并

    看到讲课安排上 线段树有一节课"区间合并" 我是迷茫的 因为并没有见过 然后了解了一下题目 发现以前写过 还是很麻烦的树链剖分 大概是 解决带修改的区间查询"连续问题&q ...

随机推荐

  1. php 图片生成器

    一.需求 最近公司由于有大量的海报要做,而且海报的布局规模都是一样的,只是内容不同,所以老板想我开发一个图片的生成器.可以根据你输入的内容生成海报图片. 具体有需求有以下的需求 1.可以根据将每条数据 ...

  2. 在linux服务器centos上使用svn同步代码到项目中

    一.需求 1.在多人开发过程中代码的管理以及版本的控制是一个很重要的问题,因为在开发过程中我们可能会同时更改过某个文件或者更改过多个文件, 这会导致我们很容易发生错误.所以我们需要一个方式去管理我们的 ...

  3. Oracle配置说明

    当Oracle安装完成后,为后续能够顺利得导出空表,特做一下配置(重点关注2.1) 1.1.查询空表select table_name from user_tables where NUM_ROWS= ...

  4. ROS-URDF-活动关节

    前言:介绍活动关节,并使机器人活动起来. 参考自:http://wiki.ros.org/urdf/Tutorials/Building%20a%20Movable%20Robot%20Model%2 ...

  5. [转载]cocos2d-触摸分发原理

    本文由泰然翻译组组长 TXX_糖炒小虾 原创,版权所有,转载请注明出处并通知作者和泰然! 原作 http://www.ityran.com/archives/1326/comment-page-1 触 ...

  6. netty 引用计数对象(reference counted objects)

    [Netty官方文档翻译]引用计数对象(reference counted objects) http://damacheng009.iteye.com/blog/2013657

  7. windows phone媒体应用开发

    MediaElement 可以播放许多不同类型的音频和视频媒体. MediaElement 是一个可以在其表面显示视频的矩形区域,也可以播放音频.MediaElement 支持触控输入事件. 使用属性 ...

  8. 关于Membership和身份认证的记录

    在今天写好的code中测试环节,当我用webconfig中的测试数据库就是ok的,但是更替为正式的就不行了: 报错的类是MemberShip,那就关系到身份认证的环节了 找了几个链接,记录下 1.身份 ...

  9. java ---书写自己的名字

    public class hello { public static void main(String[] args) { // TODO 自动生成的方法存根 System.out.println(& ...

  10. dubbo之多版本

    当一个接口实现,出现不兼容升级时,可以用版本号过渡,版本号不同的服务相互间不引用. 可以按照以下的步骤进行版本迁移: 在低压力时间段,先升级一半提供者为新版本 再将所有消费者升级为新版本 然后将剩下的 ...