hdu 1754 I hate it (线段树)
http://acm.hdu.edu.cn/showproblem.php?pid=1754
基础线段树,单点替换,区间最值。
code:
#include<algorithm>
using namespace std ;
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
const int maxn = 200010 ;
int sum[maxn<<2] ;
template <class T>
inline void scan_d(T &ret) {
char c; ret=0;
while((c=getchar())<'0'||c>'9');
while(c>='0'&&c<='9') ret=ret*10+(c-'0'),c=getchar();
}
void PushUp(int rt){
sum[rt] = max(sum[rt<<1], sum[rt<<1|1]) ;
}
void build(int l, int r, int rt){
if(l==r){
scan_d(sum[rt]) ;
return ;
}
int m = (l + r) >> 1 ;
build(lson) ;
build(rson) ;
PushUp(rt) ;
}
void update(int p, int t, int l, int r, int rt){
if(l==r){
sum[rt] = t ;
return ;
}
int m = (l + r) >> 1 ;
if(p<=m) update(p, t, lson) ;
else update(p, t, rson) ;
PushUp(rt) ;
}
int query(int L, int R, int l, int r, int rt){
if(L<=l&&r<=R){
return sum[rt] ;
}
int m = (l + r) >> 1 ;
int ret = 0 ;
if(L<=m) ret = max(ret, query(L, R, lson)) ;
if(R>m) ret = max(ret, query(L, R, rson)) ;
return ret ;
}
int main(){
int n, m, i, j, a, b ;
char c ;
while(~scanf("%d%d", &n, &m)){
build(1, n, 1) ;
while(m--){
c = getchar() ;
scan_d(a) ;
scan_d(b) ;
if(c=='U') update(a, b, 1, n, 1) ;
else printf("%d\n", query(a, b, 1, n, 1)) ;
}
}
return 0 ;}
转载于:https://www.cnblogs.com/xiaolongchase/archive/2012/05/09/2491164.html
hdu 1754 I hate it (线段树)相关推荐
- HDU 1754 I Hate It 线段树
I Hate It Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要 ...
- HDU 1166 敌兵布阵(线段树:点更新,区间求和)
HDU 1166 敌兵布阵(线段树:点更新,区间求和) http://acm.hdu.edu.cn/showproblem.php?pid=1166 题意: 给你n个整数,然后给你多条命令,每条命令如 ...
- HDU 3016 Man Down (线段树+dp)
HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- 2019CCPC网络赛 1002 HDU 6703(权值线段树)
2019CCPC网络赛 1002 HDU 6703(权值线段树) 思路:用权值线段树存题目给的数据后,2操作就是求权值线段树中大于等于k的部分中,靠近左端点的第一个大于r的值(这个求出来的只是原序列中 ...
- HDU 6070 Dirt Ratio(线段树、二分)
http://acm.hdu.edu.cn/showproblem.php?pid=6070 题解 首先不难看出错误率是单调的,那么我们可以直接二分答案x,某个区间的错误率=区间数的种类cnt/区间长 ...
- hdu 5692 Snacks(dfs序+线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5692 解题思路:这道题是树节点的点权更新,而且涉及到子树,常用的思路是利用dfs序,用线段树来对区间进 ...
- HDU 6089 Rikka with Terrorist (线段树)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=6089 题解 这波强行维护搞得我很懵逼... 扫描线,只考虑每个点能走到左上方(不包括正上方,但包括正左 ...
- hdu 4391 Paint The Wall 线段树 +优化 2012 Multi-University Training Contest 10 )
http://acm.hdu.edu.cn/showproblem.php?pid=4391 题意: 刷墙, 以开始 有 n个节点,每个节点有一种颜色 ,m 次询问 m次 输入 a,l,r,z 如果 ...
- HDU 3397 Sequence operation(线段树)
HDU 3397 Sequence operation 题目链接 题意:给定一个01序列,有5种操作 0 a b [a.b]区间置为0 1 a b [a,b]区间置为1 2 a b [a,b]区间0变 ...
- hdu 1698 Just a Hook 线段树区间更新
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 Let us number the consecutive metallic sticks of ...
最新文章
- Redis持久化机制 -全量同步与增量同步的区别
- 牛客网_PAT乙级1008_锤子剪刀布 (20)
- ES亿级数据检索优化,三秒返回突破性能瓶颈
- 华为鸿蒙os2.0系统何时搭载手机,鸿蒙OS 2.0系统正式发布!余承东:明年华为系手机将会搭载...
- 《天天数学》连载16:一月十六日
- tomcat中request对象是被创建的_Python中对象的创建与引用
- linux 查看cuda版本_Ubuntu18.04+Tensorflow GPU版本环境搭建
- 12种方法让你踏上晋升快车道。
- 入行AI,从何做起—光环飞马网直播课回顾
- 战神z7完美linux,不黑不吹 战神Z7游戏本的质量真的差么?
- 设计模式-行为型软件设计模式(六)
- 一个Layered Window从支持多屏到高DPI开始,遭遇的性能雪崩及其优化历程
- PHOTOSHOP绘制卡通人物简单教程
- 玩3D游戏头晕怎么办?为什么会头晕?如何解决?
- @张小龙 微信开机界面该升级啦!NASA帮你P了9张行星图
- Primo Ramdisk内存盘工具软件
- #203-[DFS]狼和羊
- phoenix简介及安装(附安装包)
- Rhythmbox等音乐播放器歌名乱码的解决方法
- 适配手机VR眼镜的VR视频播放器种类大全