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].

  题目大意就是给你一个数列,求区间内的最长连续子序列。以及对某一个点的值进行更改。

  线段树维护区间内的LCIS,前缀LCIS,后缀LCIS就可。

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring> #define lson L,M,po*2
#define rson M+1,R,po*2+1
#define lc po*2
#define rc po*2+1 using namespace std; const int maxn=10e5+; int mBIT[maxn*],lBIT[maxn*],rBIT[maxn*];
int num[maxn]; void pushUP(int po,int len,int M)
{
mBIT[po]=max(mBIT[lc],mBIT[rc]);
lBIT[po]=lBIT[lc];
rBIT[po]=rBIT[rc]; if(num[M]<num[M+])
{
mBIT[po]=max(mBIT[po],rBIT[lc]+lBIT[rc]); if(lBIT[lc]==len-(len/))
lBIT[po]+=lBIT[rc]; if(rBIT[rc]==(len/))
rBIT[po]+=rBIT[lc];
}
} void build_tree(int L,int R,int po)
{
if(L==R)
{
scanf("%d",&num[L]);
mBIT[po]=lBIT[po]=rBIT[po]=; return;
} int M=(L+R)/; build_tree(lson);
build_tree(rson); pushUP(po,R-L+,M);
} void update(int up,int L,int R,int po)
{
if(L==R&&L==up)
return; int M=(L+R)/; if(up<=M)
update(up,lson);
else
update(up,rson); pushUP(po,R-L+,M);
} int query(int ql,int qr,int L,int R,int po)
{
if(ql<=L&&qr>=R)
return mBIT[po]; int M=(L+R)/; if(qr<=M)
return query(ql,qr,lson);
if(ql>M)
return query(ql,qr,rson); int ans=max(query(max(ql,L),M,lson),query(M+,min(qr,R),rson));
int temp=min(rBIT[lc],M-ql+)+min(lBIT[rc],qr-M); if(num[M]<num[M+]) //这里要判断!
return max(ans,temp);
else
return ans;
} int main()
{
int N,M;
int a,b;
char c[];
int T;
cin>>T; while(T--)
{
scanf("%d %d",&N,&M); build_tree(,N-,); while(M--)
{
scanf("%s %d %d",c,&a,&b); if(c[]=='Q')
printf("%d\n",query(a,b,,N-,));
else
{
num[a]=b;
update(a,,N-,);
}
}
} return ;
}

(简单) HDU 3308 LCIS,线段树+区间合并。的更多相关文章

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

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

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

    LCIS HDU - 3308 Given n integers. You have two operations: U A B: replace the Ath number by B. (inde ...

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

    http://acm.hdu.edu.cn/showproblem.php?pid=3308 题意: 两个操作  : 1 修改 单点  a 处的值. 2 求出 区间[a,b]内的最长上升子序列. 做法 ...

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

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

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

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

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

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

  7. hdu-3308 LCIS (线段树区间合并)

    LCIS Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

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

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

  9. hdu 3308 LCIS 线段树

    昨天热身赛的简单版:LCIS.昨天那题用树链剖分,不知道哪里写错了,所以水了水这题看看合并.更新方式是否正确,发现没错啊.看来应该是在树链剖分求lca时写错了... 题目:给出n个数,有两种操作: 1 ...

  10. hdu 1540(线段树区间合并)

    题目链接:传送门 参考文章:传送门 题意:n个数字初始连在一条线上,有三种操作, D x表示x号被摧毁: R 表示恢复剩下的通路 Q表示查询标号为x所在的串的最长长度. 思路:线段树的区间合并. #i ...

随机推荐

  1. linux的学习系列 5--环境变量

    在Linux中,环境变量是一个很重要的概念.环境变量可以由系统.用户.Shell以及其他程序来设定. 变量就是一个可以被赋值的字符串,赋值范围包括数字.文本.文件名.设备以及其他类型的数据. 下面的例 ...

  2. 华哥倒酒<区间标记,二分>

    题目链接 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; t ...

  3. C++builder编译别人工程报错

    编译时遇到错误,信息如下: [C++ Error] NVRAMEditor.h(83): E2209 Unable to open include file 'CONTROLSLib_OCX.h'[C ...

  4. HDU 4460 Friend Chains(map + spfa)

    Friend Chains Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total ...

  5. PAT (Advanced Level) 1098. Insertion or Heap Sort (25)

    简单题.判断一下是插排还是堆排. #include<cstdio> #include<cstring> #include<cmath> #include<ve ...

  6. Redis(1)在windows环境下的安装和测试

    初次准备使用redis,一个著名的nosql缓存数据库. 这里是第一天,就简单写一下windows下的安装,遇到的一些问题,然后简单的使用和测试,之后会在代码中使用和测试. 之后还会在生产环境中进行测 ...

  7. ASP.NET中的Response

    Response.BufferOutput=true.false  是否设置缓存 Response.Write("")   输出字符串 Response.IsClientConne ...

  8. C# 经典入门15章-TextBoxControl

    第一步:设计界面如下:

  9. jQuery+CSS实现的图片滚动效果

    http://www.helloweba.com/view-blog-139.html

  10. whm 设置共享IP

    点击 Main >>Resellers>>resellers centers (manages ressellers center's IP有几个IP代表几个)