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的学习系列 4---文件权限和访问模式

    为了更加安全的存储文件,Linux为不同的文件赋予了不同的权限,每个文件都拥有下面三种权限: 所有者权限:文件所有者能够进行的操作 组权限:文件所属用户组能够进行的操作 外部权限(其他权限):其他用户 ...

  2. HttpSession详解

    HttpSession详解   session的机制 http是无状态的协议,客户每次读取web页面时,服务器都打开新的会话,而且服务器也不会自动维护客户的上下文信息,那么要怎么才能实现会话跟踪呢?s ...

  3. C --> OC with RunTime

    前言 本来打算写一篇关于runtime的学习总结,无奈长篇大论不是我的风格,就像写申论一样痛苦,加之网上关于tuntime的文章多如牛毛,应该也够童子们学习的了,今天就随便聊聊我的理解吧. runti ...

  4. std::function 测试

    #ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" typedef ...

  5. android 在代码中使用 #ffffff 模式 设置背景色

    differentsum.setBackgroundColor(Color.parseColor("#F3733F"));

  6. HDU 2674 N!Again

    一开始以为有循环节,输出了前100项发现n>40都是0.因此,水题.... #include<cstdio> ]; ; int main() { a[]=; ; i<=; i+ ...

  7. Chapter 1 First Sight——18

    But at least he sent me to an empty desk at the back without introducing me to the class. 但是最后他给我最后面 ...

  8. Entity Framework 6新功能Logging/Store Procedure

    摘要 在Entity Framework6中有两个新的功能,DB Loggin和Stored Procedure的映射 Entity Framework 6已经从Beta版本来到了RC1版本,我们可以 ...

  9. 转 spring security的使用

    [转自:http://haohaoxuexi.iteye.com/blog/2154714] 关于登录 目录 1.1     form-login元素介绍 1.1.1    使用自定义登录页面 1.1 ...

  10. space 管理

    输入:表空间名字 输出:表空间下的一个文件即退出 /tmp/.sql select name from v$database; set serveroutput on; declare i1 varc ...