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 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求, ...
随机推荐
- Spring+Hibernate整合
因为整合spring和hibernate所以,需要用到spring里面复写Hibernate的类以有DI和IOC特性 db.sql hibernate_basic数据库 表 person 字段 pid ...
- 【转帖】Servlet 3.0 新特性详解
http://www.ibm.com/developerworks/cn/java/j-lo-servlet30/ Servlet 3.0 新特性概述 Servlet 3.0 作为 Java EE 6 ...
- 关于UML图形/图示数量总结
http://www.uml.org/ 第一种说法: UML - Unified Modeling Language UML 共定义了9种图,包括4种结构图和5种形为图: //4种结构图: 类图 对象 ...
- Ubuntu11.04中如何将pycharm添加到系统的“应用程序”菜单里 (pycharm已成功安装)
默认排序 Stu.zhouyc 21 人赞同了该回答 tools---->create desktop entry...不是很方便吗? 发布于 2016-04-09 21添加评论 分享 收藏 ...
- 服务发现与负载均衡 dubbo zk原理
服务发现与负载均衡 拓展阅读 : dubbo 原理概念图 2016-03-03 杜亦舒 性能与架构 性能与架构 性能与架构 微信号 yogoup 功能介绍 网站性能提升与架构设计 内容整理自文章“实施 ...
- git问题:git提交的时候总是提示key加载失败,总是需要手工将key加到Pageant中
问题描述: 重装过一次系统,在重装之前git+tortoisegit配合很好,提交的时候都能自动加载ppk,但是重装系统后,也重新生成pulic key上传到了服务器,但是每次提交的时候都提示key加 ...
- 多线程-Condition
关键字synchronized与wait和notify/notifyAll方法相结合可以实现等待/通知模式,类ReentrantLock也可以实现同样的功能,但需要借助于Condition对象.Con ...
- atitit.提升性能AppCache
atitit.提升性能AppCache 1.1. 起源1 2. 离线存储2 3. AppCache2 3.1. Appcache事件点如图2 3.2. Manifest文件4 3.3. 自动化工具4 ...
- DockPanel的使用
1.建立一个WinForm工程,默认生成了一个WinForm窗体Form1. 2.引用—>添加引用—>浏览—>weiFenLuo.winFormsUI.Docking.dll. 3. ...
- mysql数据库分库备份脚本
mysql数据库分库备份脚本 版本1 for dbname in `mysql -uroot -poldboy123 -e "show databases;" |grep -Evi ...