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 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求, ...
随机推荐
- Qt for Android 开发大坑
Qt for Android 开发大坑 作者: qyvlik Qt 5.5.1 这里说一说比較常见的 Qt 开发安卓的大坑. 希望同学们不要做无谓的挣扎,跳过这些坑. 输入框 首当其冲的是输入框,Qt ...
- DS18B20 crc 算法
http://blog.csdn.net/pengrui18/article/details/24740973 https://www.maximintegrated.com/cn/app-notes ...
- zookeeper(一):功能和原理
简介 ZooKeeper 是一个开源的分布式协调服务,由雅虎创建,是 Google Chubby 的开源实现.分布式应用程序可以基于 ZooKeeper 实现诸如数据发布/订阅.负载均衡.命名服务.分 ...
- Windows 2003 远程桌面
- 多线程-ThreadLocal,InheritableThreadLocal
ThreadLocal 变量值得共享可以使用public static变量的形式,所有的线程都使用同一个public static变量.如果想实现每一个线程都有自己的共享变量该如何解决呢?JDK中提供 ...
- Missing iOS Distribution signing identity for …, 在打包的时候发现证书过期了。
今天早上 上班发现钥匙串中的全部证书 都 提示此证书签发者无效 Thanks for bringing this to the attention of the community and apolo ...
- MooseFS管理
一.goal(副本) 副本,在MFS中也被称为目标(Goal),它是指文件被复制的份数,设定目标值后可以通过mfsgetgoal命令来证实,也可以通过mfssetgoal命令来改变设定. 1 2 3 ...
- 第一篇:初识python
1.python介绍 Python, 是一种面向对象的解释型计算机程序设计语言,由荷兰人Guido van Rossum于1989年发明,第一个公开发行版发行于1991年. Python的官方介绍是: ...
- mysql之内存表
一.引言 昨天下午老大让我查资料看一下mysql的内存表在主从备份中是否能被复制,我还没听说过内存表呢,于是上网查资料,记录一下,以便查阅.学习 二.进展 参考: http://www.cnblogs ...
- Oracle 错误 maximum number of processes(150) exceeded 解决办法
网上很多同行应该都遇到过这个问题,百度一搜 千篇一律的处理办法,就是加大进程数. 但是我这边情况不一样,因为我的Oracle 11g是早上刚装的,跟本没人用,我用PLSQL链接照样说不能链接. 我就在 ...