HDU 3308 LCIS
题意:
U A B: 把第A个数变成B
Q A B: 输出【A,B】最长连续上升子序列(注意是连续 相当于子串)
思路:单点更新 ,区间合并几下左边开头最小 和右边结束最大的两个数即可。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include <iostream>
#define lson (i<<1)
#define rson (i<<1|1)
#define N 100050
using namespace std;
int lsum[N*],rsum[N*],msum[N*];
int lmaxn[N*],rmaxn[N*];
int a[N];
int max(int x,int y)
{
return x>y?x:y;
}
int min(int x,int y)
{
return x<y?x:y;
}
void pushup(int i,int l,int r)
{
int mid=(l+r)>>;
lsum[i]=lsum[lson];
rsum[i]=rsum[rson];
if(lsum[i]==mid-l+&&rmaxn[lson]<lmaxn[rson])
lsum[i]+=lsum[rson];
if(rsum[i]==r-mid&&rmaxn[lson]<lmaxn[rson])
rsum[i]+=rsum[lson];
msum[i]=max(msum[lson],msum[rson]);
if(rmaxn[lson]<lmaxn[rson])
msum[i]=max(msum[i],rsum[lson]+lsum[rson]);
lmaxn[i]=lmaxn[lson];
rmaxn[i]=rmaxn[rson];
}
void build(int l,int r,int i)
{
if(l==r)
{
lsum[i]=rsum[i]=msum[i]=; lmaxn[i]=rmaxn[i]=a[l];
return ;
}
int mid=(l+r)>>;
build(l,mid,lson);
build(mid+,r,rson);
pushup(i,l,r);
}
void update(int l,int r,int p,int va,int i)
{
if(l==r)
{
lmaxn[i]=rmaxn[i]=va;
return ;
}
int mid=(l+r)>>;
if(p<=mid)update(l,mid,p,va,lson);
else update(mid+,r,p,va,rson);
pushup(i,l,r);
}
int query(int l,int r,int pl,int pr,int i)
{
if(l>=pl&&r<=pr)
{
return msum[i];
}
int mid=(l+r)>>;
if(pr<=mid)return query(l,mid,pl,pr,lson);
else if(pl>mid)return query(mid+,r,pl,pr,rson);
else
{ int maxn1=,maxn2=;
maxn1=query(l,mid,pl,mid,lson);
maxn2=query(mid+,r,mid+,pr,rson);
maxn1=max(maxn1,maxn2);
if(rmaxn[lson]<lmaxn[rson])
{
int tmp=min(rsum[lson],mid-pl+)+min(lsum[rson],pr-mid);
maxn1=max(maxn1,tmp);
}
return maxn1;
}
}
int main() {
int tt,n,m;
scanf("%d",&tt);
while(tt--)
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;++i)
scanf("%d",&a[i]);
build(,n,);
while(m--)
{
char c;
int l,r;
scanf(" %c%d%d",&c,&l,&r); if(c=='U')
{
l++;
update(,n,l,r,);
}else
{
l++;r++;
printf("%d\n",query(,n,l,r,));
}
}
}
return ;
}
HDU 3308 LCIS的更多相关文章
- hdu 3308 LCIS(线段树区间合并)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=3308 LCIS Time Limit: 6000/2000 MS (Java/Others) ...
- HDU 3308 LCIS (线段树区间合并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 题目很好懂,就是单点更新,然后求区间的最长上升子序列. 线段树区间合并问题,注意合并的条件是a[ ...
- HDU 3308 LCIS(线段树)
Problem Description Given n integers.You have two operations:U A B: replace the Ath number by B. (in ...
- hdu 3308 LCIS 线段树
昨天热身赛的简单版:LCIS.昨天那题用树链剖分,不知道哪里写错了,所以水了水这题看看合并.更新方式是否正确,发现没错啊.看来应该是在树链剖分求lca时写错了... 题目:给出n个数,有两种操作: 1 ...
- 线段树(区间维护):HDU 3308 LCIS
LCIS Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 3308 LCIS(线段树单点更新区间合并)
LCIS Given n integers. You have two operations: U A B: replace the Ath number by B. (index counting ...
- (简单) HDU 3308 LCIS,线段树+区间合并。
Problem Description Given n integers. You have two operations: U A B: replace the Ath number by B. ( ...
- HDU 3308 LCIS (经典区间合并)【线段树】
<题目链接> 题目大意: 给你一段序列,对其进行两种操作,一是修改某个序号的点的值:二是查询某个区间的LCIS(最长上升子序列). 解题分析: 线段树区间合并的典型例题,用求某个区间的LC ...
- HDU 3308 LCIS (线段树·单点更新·区间合并)
题意 给你一个数组 有更新值和查询两种操作 对于每次查询 输出相应区间的最长连续递增子序列的长度 基础的线段树区间合并 线段树维护三个值 相应区间的LCIS长度(lcis) 相应区间以左 ...
- HDU 3308 LCIS(线段树)
题目链接 模板题吧,忘了好多,终于A了... #include <cstring> #include <cstdio> #include <string> #inc ...
随机推荐
- Codeforces 749B:Parallelogram is Back(计算几何)
http://codeforces.com/problemset/problem/749/B 题意:已知平行四边形三个顶点,求另外一个顶点可能的位置. 思路:用向量来做. #include <c ...
- 模板引擎:ArtTemplate 使用入门和简单的使用
下载地址:https://github.com/aui/artTemplate 快速上手请参考:https://github.com/aui/artTemplate 通过阅读artTemplate原文 ...
- 微信JS SDK PHP Demo
一.JSSDK类定义 <?php class JSSDK { private $appId; private $appSecret; public function __construct($a ...
- Linux 各文件夹介绍
http://www.cnblogs.com/amboyna/archive/2008/02/16/1070474.html linux下的文件结构,看看每个文件夹都是干吗用的/bin 二进制可执行命 ...
- Python3基础 sort 将一个列表中的值升序排列
镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...
- sql 、linq、lambda 查询语句的区别
LINQ的书写格式如下: from 临时变量 in 集合对象或数据库对象 where 条件表达式 [order by条件] select 临时变量中被查询的值 [group by 条件] Lambda ...
- mysql 日期格式化
SELECT plc.id, plc.policy_no, plc.out_date, og.organ_name, ir.insurer_name, pd.product_name, plc.pol ...
- ajax是异步的,异步取数据,如何能保证数据是存在的。
https://segmentfault.com/q/1010000002964172 ajax是异步的,所以aa()在执行的时候,return的那个result本身就是空的,在此后的某些秒以后,re ...
- onethink使用经验
1 建议随时从oschina上下载onethink的最新版本,如果你遇到了怎么都解决不了的问题,比如菜单管理自定义菜单,左侧二级菜单不显示的问题,好像有一个历史版本就是有bug,好像是1.1开始的一个 ...
- Js综合笔记
-----网页禁止复制---- -----网页禁止复制---- <body> <SCRIPT language=javascript type=text/javascript> ...