kuangbin_SegTree B (HDU 1754)
跟A题类似 只是把update从增减直接改为赋值 query从求和改为求最大值 其他几乎一样
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#define INF 0x3f3f3f3f
#define lson l, m, root<<1
#define rson m+1, r, root<<1|1
using namespace std; const int MAXN = 2e5+;
int val[MAXN*]; void pushup(int root)
{
val[root] = max(val[root<<], val[root<<|]);
} void build(int l, int r, int root)
{
if(l == r) scanf("%d", &val[root]);
else{
int m = (l + r) >> ;
build(lson);
build(rson);
pushup(root);
}
} void update(int point, int value, int l, int r, int root)
{
if(l == r) val[root] = value;
else{
int m = (l + r) >> ;
if(point <= m) update(point, value, lson);
else update(point, value, rson);
pushup(root);
}
} int query(int L, int R, int l, int r, int root)
{
if(L <= l && R >= r) return val[root];
int res = ;
int m = (l + r) >> ;
if(L <= m) res = max(res, query(L, R, lson));
if(R > m) res = max(res, query(L, R, rson));
return res;
} int main()
{
int n, m;
while(~scanf("%d%d", &n, &m)){
build(, n, );
char op[];
while(m--){
scanf("%s", op);
int u, v;
scanf("%d%d", &u, &v);
if(op[] == 'U') update(u, v, , n, );
else{
if(u > v) swap(u, v);
printf("%d\n", query(u, v, , n, ));
}
}
}
return ;
}
kuangbin_SegTree B (HDU 1754)的更多相关文章
- hdu 1754 Ihate it
I Hate It Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- hdu 1754 I Hate It (splay tree伸展树)
hdu 1754 I Hate It 其实我只是来存一下我的splay模板的..请大牛们多多指教 #include<stdio.h> #include<string.h> #i ...
- hdu 1754 线段树(Max+单点修改)
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu 1754 I Hate It (线段树功能:单点更新和区间最值)
版权声明:本文为博主原创文章.未经博主同意不得转载.vasttian https://blog.csdn.net/u012860063/article/details/32982923 转载请注明出处 ...
- HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)
HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...
- HDU 1754——I Hate It——————【线段树单点替换、区间求最大值】
I Hate It Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit St ...
- 线段树(单点更新) HDU 1754 I Hate It
题目传送门 /* 线段树基本功能:区间最大值,修改某个值 */ #include <cstdio> #include <cstring> #include <algori ...
- hdu 1754 I Hate It 线段树 点改动
// hdu 1754 I Hate It 线段树 点改动 // // 不多说,裸的点改动 // // 继续练 #include <algorithm> #include <bits ...
- hdu 1754 I Hate It (模板线段树)
http://acm.hdu.edu.cn/showproblem.php?pid=1754 I Hate It Time Limit: 9000/3000 MS (Java/Others) M ...
随机推荐
- HTML基础(1)
1.前端开发语言介绍 HTML(Hypertext Markup Language)—— 结构—— 超文本标记语言 CSS(Cascading Style Sheets)—— 样式—— 层叠样式表 J ...
- Unquotted string '"2016-07-19"'
自己挖的坑,含泪跳进去也要填平. ---题记 1.问题: a. 在前端使用JSON.stringify(json)转化数组对象为字符串,然后传给后台: var dateArray = new Ar ...
- win安装NLTK出现的问题
一.今天学习Python自然语言处理(NLP processing) 需要安装自然语言工具包NLTK Natural Language Toolkit 按照教程在官网https://pypi.pyth ...
- 正则神器,RegexBuddy
解释 转换 测试匹配 使用帮助 正则图书馆 转为PHP案例 功能强大,虽然是英文的!挺不错的~
- Deep Learning 2_深度学习UFLDL教程:矢量化编程(斯坦福大学深度学习教程)
1前言 本节主要是让人用矢量化编程代替效率比较低的for循环. 在前一节的Sparse Autoencoder练习中已经实现了矢量化编程,所以与前一节的区别只在于本节训练集是用MINIST数据集,而上 ...
- mysql导入导出数据中文乱码解决方法小结
linux系统中 linux默认的是utf8编码,而windows是gbk编码,所以会出现上面的乱码问题. 解决mysql导入导出数据乱码问题 首先要做的是要确定你导出数据的编码格式,使用mysqld ...
- UIScrollView 原理详解
转载此文章原因:web页面在ipad的app中总是有橡皮筋效果,使用iscroll虽然能解决橡皮筋想过,但是滚动层内的元素事件都无法触发.故同安卓和ios一样使用后台解决...红色的为解决方案.. S ...
- 使用Git进行代码管理的心得
使用GitHub进行代码托管的方法 我是直接下载 Github for Windows ,这个软件自带一个 Github 客户端 和一个 Git shell,其中Github是图形化界面,对初学者来说 ...
- bzoj 3130: [Sdoi2013]费用流
#include<cstdio> #include<iostream> #define M 10000 #define inf 0x7fffffff #include<c ...
- Activity启动清空原任务栈
就是 启动新的activity 但是把之前所有的activity 都finish掉 而且所有的activity 都是在一个栈中 Intent intent = new Intent();intent ...