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 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求, ...
随机推荐
- Oracle SQL Developer出现错误 【ora-28002:the password will expire within 7 days】的解决办法
启动 Oracle SQL Developer的时候,点击用户system进行连接并输入密码后(下图左),会出现(下图右)提示信息: 即:[ora-28002:the password will ex ...
- 采集Snoopy.class.php
<?php /************************************************* Snoopy - the PHP net client Author: Mont ...
- 解决在IE9,IE10浏览器下,程序没有任何错误,easy ui页面不加载任何数据的问题
对于web应用程序,经常用到开发人员工具,按F12,可以调试脚本,可以查看监视网络,查看各页面加载时间,非常方便,今天在调试js时,不小心打开了兼容性视图, 之后每次打打开页面时,均不显示页面post ...
- 几种TCP连接中出现RST的情况(转载)
TCP RST 网络 linux 目录[-] 1 端口未打开 2 请求超时 3 提前关闭 4 在一个已关闭的socket上收到数据 总结 参考文献: 应该没有人会质疑,现在是一个网络时代了.应该不少程 ...
- DEDECMS 添加栏目图片
当我们一个栏目列表都用缩略图来表示产,而不仅仅只是文字,如果没有这项功能会非常麻烦,网上有很多这方面的资料,但是都试过了有很多问题,自己研究一下,测试基本通过.需要新加字段 typeimg 后台执行S ...
- 自己动手写CPU之第五阶段(2)——OpenMIPS对数据相关问题的解决措施
将陆续上传本人写的新书<自己动手写CPU>(尚未出版).今天是第16篇.我尽量每周四篇 5.2 OpenMIPS对数据相关问题的解决措施 OpenMIPS处理器採用数据前推的方法来解决流水 ...
- hsqldb
http://www.hsqldb.org/ HSQLDB (HyperSQL DataBase) is the leading SQL relational database software wr ...
- springboot+springAOP实现数据库读写分离及数据库同步(MySQL)----最新可用2019-2-14
原文:https://blog.csdn.net/wsbgmofo/article/details/79260896 1,数据源配置文件,如下 datasource.readSize=1spring. ...
- django中使用POST方法 使用ajax后出现“CSRF token missing or incorrect”
这个是因为在django的ajax中默认添加了token,因此需要在cookie中增加token头信息. 首先使用JavaScript函数获取token: function getCookie(nam ...
- CCNA2.0笔记_STP
STP介绍 STP的主要任务是阻止在第二层网络(网桥或交换机)上产生网络环路(通过将特定的端口选为 Blocking state),来实现无环的拓扑 ; STP交换机之间使用Trunk连接 ; Cis ...