HDU3308(LCIS) 线段树好题
题目链接:传送门
题目大意:给你n个数,m个操作。操作有两种:1.U x y 将数组第x位变为y 2. Q x y 问数组第x位到第y位连续最长子序列的长度。对于每次询问,输出一个答案
题目思路:线段树单点修改区间合并
这道题题目好在对pushup的理解,我们在向上更新的时候有注意情况的区分
1.如果左区间的最右边的值小于右区间最左边的值,则有一个待定答案是左儿子的右区间+右儿子的左区间
2.如果不符合第一个条件,则有一个待定答案是左区间最大值和右区间最大值中较大的那一个。
有一点要特别注意:如果当前区间中所有的值都符合上升序列,那么更新它的父节点时,它可以加上其他区间的边界值而进行扩充
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cctype>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <climits>
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define fi first
#define se second
#define ping(x,y) ((x-y)*(x-y))
#define mst(x,y) memset(x,y,sizeof(x))
#define mcp(x,y) memcpy(x,y,sizeof(y))
using namespace std;
#define gamma 0.5772156649015328606065120
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define N 100005
#define maxn 50005
typedef pair<int,int> PII;
typedef long long LL;
const double pi=acos(-1.0);
const double e=2.718281828459; int n,m,k,x,y;
int no[N<<],ls[N<<],rs[N<<];
int a[N];
inline void pushup(int rt,int l,int r){
int mid=l+r>>;
ls[rt]=ls[rt<<];rs[rt]=rs[rt<<|];
no[rt]=max(no[rt<<],no[rt<<|]);
if(a[mid]<a[mid+]){
if(ls[rt]==mid-l+)ls[rt]+=ls[rt<<|];
if(rs[rt]==r-mid)rs[rt]+=rs[rt<<];
no[rt]=max(no[rt],ls[rt<<|]+rs[rt<<]);
}
}
void build(int rt,int l,int r){
if(l==r){
no[rt]=ls[rt]=rs[rt]=;
return;
}
int mid=l+r>>;
build(lson);build(rson);
pushup(rt,l,r);
}
void add(int rt,int l,int r){
if(l==r){return;}
int mid=l+r>>;
if(x<=mid)add(lson);
else add(rson);
pushup(rt,l,r);
}
int query(int rt,int l,int r){
if(x<=l&&r<=y)return no[rt];
int mid=l+r>>;
if(y<=mid)return query(lson);
if(x>mid)return query(rson);
int t1=query(lson);
int t2=query(rson);
int ans=max(t1,t2);
if(a[mid]<a[mid+]){
ans=max(ans,(min(ls[rt<<|],y-mid)+min(rs[rt<<],mid+-x)));
}
return ans;
}
int main(){
int i,j,group;
scanf("%d",&group);
while(group--){
char str[];
scanf("%d%d",&n,&m);
for(i=;i<=n;++i)scanf("%d",&a[i]);
build(,,n);
while(m--){
scanf("%s%d%d",str,&x,&y);
++x;
if(str[]=='U'){a[x]=y;add(,,n);}
else{++y;printf("%d\n",query(,,n));}
}
}
return ;
}
HDU3308(LCIS) 线段树好题的更多相关文章
- hdu-3308 LCIS (线段树区间合并)
LCIS Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- [AHOI 2009] 维护序列(线段树模板题)
1798: [Ahoi2009]Seq 维护序列seq Time Limit: 30 Sec Memory Limit: 64 MB Description 老师交给小可可一个维护数列的任务,现在小 ...
- POJ 3468 线段树裸题
这些天一直在看线段树,因为临近期末,所以看得断断续续,弄得有些知识点没能理解得很透切,但我也知道不能钻牛角尖,所以配合着刷题来加深理解. 然后,这是线段树裸题,而且是最简单的区间增加与查询,我参考了A ...
- hdu-1540线段树刷题
title: hdu-1540线段树刷题 date: 2018-10-18 19:55:21 tags: acm 刷题 categories: ACM-线段树 概述 哇,,,这道线段树的题可以说是到目 ...
- hdu-5023线段树刷题
title: hdu-5023线段树刷题 date: 2018-10-18 13:32:13 tags: acm 刷题 categories: ACM-线段树 概述 这道题和上次做的那道染色问题一样, ...
- poj-2777线段树刷题
title: poj-2777线段树刷题 date: 2018-10-16 20:01:07 tags: acm 刷题 categories: ACM-线段树 概述 这道题是一道线段树的染色问题,,, ...
- zoj-1610线段树刷题
title: zoj-1610线段树刷题 date: 2018-10-16 16:49:47 tags: acm 刷题 categories: ACM-线段树 概述 这道题是一道简单的线段树区间染色问 ...
- Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) E - Nikita and stack 线段树好题
http://codeforces.com/contest/760/problem/E 题目大意:现在对栈有m个操作,但是顺序是乱的,现在每输入一个操作要求你输出当前的栈顶, 注意,已有操作要按它们的 ...
- hdu 1754 I Hate It 线段树基础题
Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求, ...
随机推荐
- 电子商务(电销)平台中用户模块(User)数据库设计明细(转载)
电子商务(电销)平台中用户模块(User)数据库设计明细 以下是自己在电子商务系统设计中的订单模块的数据库设计经验总结,而今发表出来一起分享,如有不当,欢迎跟帖讨论~ 用户基础表(user_base) ...
- photoshop 动作 自己定义快捷键 播放选定的动作
今天在制作一组效果图.要用到动作.而且是同一个动作,便在网上寻找"播放选定的动作"就是那个三角形播放button的快捷键. 预期这样会大大加快制作过程. 首先制作好动作. 然后,在 ...
- .net4 dynamic parse xml
using System.Collections.Generic; using System.Linq; using System.Xml.Linq; using System.Dynamic; na ...
- kali2.0下配置Metasploit+postgresql链接
工具/原料 kali2.0 方法/步骤 1.postgresql是本身没有启动的.所以需要启动. service postgresql start 2.通过命令进入配置 sudo -u ...
- NoReverseMatch at /salesman/zhuce/ Reverse for '/zhuce/' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
NoReverseMatch at /salesman/zhuce/ Reverse for '/zhuce/' with arguments '()' and keyword arguments ' ...
- yum安装方式的php,切换NTS为ZTS版本
用 yum安装方式的php,切换NTS为ZTS版本(切换为线程安全版本) 最好按我这个方法安装(安装比较全一点): https://www.cnblogs.com/fps2tao/p/7699448. ...
- 如何在mysql下实现事务的提交与回滚
最近要对数据库的数据进行一个定时迁移,为了防止在执行过程sql语句因为某些原因报错而导致数据转移混乱,因此要对我们的脚本加以事务进行控制. 首先我们建一张tran_test表 CREATE TABLE ...
- javascript和html中unicode编码和字符转义的详解
1.html中的转义:在html中如果遇到转义字符(如“ ”),不管你的页面字符编码是utf-8亦或者是GB2312,都会直接打印成相应的字符:而当遇到(如:“\u8981”[此处的8981是16进制 ...
- unity, 不要用TextMesh,用图片代替
<方块鸭快跑>(见:http://www.cnblogs.com/wantnon/p/4596222.html)1.0版本开始界面中鸭子的speech bubble中的文字用的是TextM ...
- 统一修改 UINavigationBar backItem
{ UINavigationBar * navigationBar = [UINavigationBar appearance]; //返回按钮的箭头颜色 [navigationBar setTint ...