hdu_1754,线段树单点更新,求区间最值
http://www.notonlysuccess.com/index.php/segment-tree-complete/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define maxn 2222222
using namespace std;
int a[maxn<<2];
void pushUp(int rt)
{
a[rt]=max(a[rt<<1],a[rt<<1|1]);
}
void build(int l,int r,int rt)
{
if(l==r)
{
scanf("%d",&a[rt]);
return ;
}
int m=(r+l)>>1;
build(lson);
build(rson);
pushUp(rt);
}
void update(int p,int sc,int l,int r,int rt)
{
if(l==r)
{
a[rt]=sc;
return;
}
int m=(l+r)>>1;
if(p<=m) update(p,sc,lson);
else update(p,sc,rson);
pushUp(rt);
}
int query(int L,int R,int l,int r,int rt)
{
int x=0;
if(L<=l&&r<=R)
return a[rt];
int m=(r+l)>>1;
if(L<=m) x=max(x,query(L,R,lson));
if(R>m) x=max(x,query(L,R,rson));
return x;
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
build(1,n,1);
char c[2];
int d,e;
for(int i=0; i<m; i++)
{
scanf("%s%d%d",c,&d,&e);
if(c[0]=='Q')
{
printf("%d\n",query(d,e,1,n,1));
}
if(c[0]=='U')
{
update(d,e,1,n,1);
}
}
}
return 0;
}
hdu_1754,线段树单点更新,求区间最值的更多相关文章
- HDU 2795 Billboard (线段树单点更新 && 求区间最值位置)
题意 : 有一块 h * w 的公告板,现在往上面贴 n 张长恒为 1 宽为 wi 的公告,每次贴的地方都是尽量靠左靠上,问你每一张公告将被贴在1~h的哪一行?按照输入顺序给出. 分析 : 这道题说明 ...
- HDU 1754 I Hate It 线段树单点更新求最大值
题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...
- poj 2892---Tunnel Warfare(线段树单点更新、区间合并)
题目链接 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensiv ...
- 计蒜客 28315.Excellent Engineers-线段树(单点更新、区间最值) (Benelux Algorithm Programming Contest 2014 Final ACM-ICPC Asia Training League 暑假第一阶段第二场 E)
先写这几道题,比赛的时候有事就只签了个到. 题目传送门 E. Excellent Engineers 传送门 这个题的意思就是如果一个人的r1,r2,r3中的某一个比已存在的人中的小,就把这个人添加到 ...
- HDU 1394 Minimum Inversion Number (线段树 单点更新 求逆序数)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 题意:给你一个n个数的序列,当中组成的数仅仅有0-n,我们能够进行这么一种操作:把第一个数移到最 ...
- hdoj 2795 Billboard 【线段树 单点更新 + 维护区间最大值】
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- BZOJ 1012: [JSOI2008]最大数maxnumber【线段树单点更新求最值,单调队列,多解】
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 10374 Solved: 4535[Subm ...
- HDU 1754.I Hate It-完全版线段树(单点替换、区间最值)
HDU1754.I Hate It 直接模板就可以了 代码: //B #include<iostream> #include<cstdio> #include<cstri ...
- nyoj 568——RMQ with Shifts——————【线段树单点更新、区间求最值】
RMQ with Shifts 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 In the traditional RMQ (Range Minimum Q ...
- hdu 1754 线段树 单点更新 动态区间最大值
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
随机推荐
- 高级函数-decode
decode(字段或计算表达式, 条件值1,结果值1, 条件值2,结果值2[,默认值] ) if(字段或计算表达式 == 条件值1 ...
- BZOJ——1787: [Ahoi2008]Meet 紧急集合
http://www.lydsy.com/JudgeOnline/problem.php?id=1787 题目描述 输入 输出 样例输入 6 4 1 2 2 3 2 4 4 5 5 6 4 5 6 6 ...
- 晋IT分享成长沙龙集锦
第一期"晋IT"分享成长沙龙于2014年7月19日圆满结束.下面是相关内容整理和第二期预告. 各位伙伴认真的介绍自己,介绍自己的业务,分析自己眼下存在的问题,大家一起探讨,真诚出谋 ...
- node11---相册
app.js /* littleAlbum --.idea --controller(控制层相当于action层) --package.json --router.js --models(做事的是mo ...
- bzoj1797: [Ahoi2009]Mincut 最小割(最小割+强联通tarjan)
1797: [Ahoi2009]Mincut 最小割 题目:传送门 题解: 感觉是一道肥肠好的题目. 第二问其实比第一问简单? 用残余网络跑强联通,流量大于0才访问. 那么如果两个点所属的联通分量分别 ...
- 官方文档 Upgrading Elasticsearch
Upgrading Elasticsearch Before upgrading Elasticsearch: Consult the breaking changes docs. Use the E ...
- nyoj--1237--最大岛屿(dfs+数据处理)
最大岛屿 时间限制:1000 ms | 内存限制:65535 KB 难度: 描述 神秘的海洋,惊险的探险之路,打捞海底宝藏,激烈的海战,海盗劫富等等.加勒比海盗,你知道吧?杰克船长驾驶着自己的的战 ...
- 一题多解(一) —— list(Python)判空(以及 is 与 == 的区别)
>> l = [] 1. == >> l == [] True 2. not >> not l True 3. 注意 is 与 == 的区别 >> l ...
- sicily 1002 Anti-prime Sequences
debug了好久..各种犯错..按照某个学长的思路,终于AC了.. #include <iostream> #include <cstring> using namespace ...
- 2019Pycharm激活方法
1.将“0.0.0.0 account.jetbrains.com”添加到hosts文件中 2.打开http://idea.lanyus.com/ 3.获取激活码,粘贴到第二个选项中 亲测可用.