题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754

线段树模板题,update功能是单点替换,query是访问区间最大值。

#include <stdio.h>
#include <algorithm> using namespace std; #define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
const int maxn = ;
int MAX[maxn<<]; void PushUP(int rt)
{
MAX[rt]=max(MAX[rt<<],MAX[rt<<|]);
} void build(int l,int r,int rt)
{
if(l==r)
{
scanf("%d",&MAX[rt]);
return ;
}
int m = (l+r)>>;
build(lson);
build(rson);
PushUP(rt);
} void update(int p,int sc,int l,int r,int rt)
{
if(l==r)
{
MAX[rt] = sc;
return ;
}
int m = (l+r)>>;
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)
{
if(L<=l&&r<=R)
return MAX[rt];
int m = (l+r)>>;
int ret = ;
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;
while(scanf("%d%d",&n,&m)!=EOF)
{
build(,n,);
while(m--)
{
char ch[];
int a,b;
scanf("%s%d%d",ch,&a,&b);
if(ch[]=='Q')
{
printf("%d\n",query(a,b,,n,));
}
else
update(a,b,,n,);
}
}
return ;
}

HDU(1754),线段树,单点替换,区间最值的更多相关文章

  1. I Hate It HDU - 1754 线段树 单点修改+区间最值

    #include<iostream> #include<cstring> using namespace std; ; int m,n,p; struct node{ int ...

  2. HDU 1754 I Hate It(线段树单点替换+区间最值)

    I Hate It [题目链接]I Hate It [题目类型]线段树单点替换+区间最值 &题意: 本题目包含多组测试,请处理到文件结束. 在每个测试的第一行,有两个正整数 N 和 M ( 0 ...

  3. hdu1754(线段树单点替换&区间最值模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 题意:中文题诶- 思路:线段树单点替换&区间最大值查询模板 代码: #include & ...

  4. hdu 1166线段树 单点更新 区间求和

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  5. HDU 1754 线段树 单点跟新 HDU 1166 敌兵布阵 线段树 区间求和

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. hdu2795(线段树单点更新&区间最值)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题意:有一个 h * w 的板子,要在上面贴 n 条 1 * x 的广告,在贴第 i 条广告时要 ...

  7. 【HDU】1754 I hate it ——线段树 单点更新 区间最值

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  8. HDU - 1754 线段树-单点修改+询问区间最大值

    这个也是线段树的经验问题,待修改的,动态询问区间的最大值,只需要每次更新的时候,去把利用子节点的信息进行修改即可以. 注意更新的时候区间的选择,需要对区间进行二分. #include<iostr ...

  9. hdu 1754 I Hate It 线段树 单点更新 区间最值

    线段树功能:update:单点更新 query:区间最值 #include <bits/stdc++.h> #define lson l, m, rt<<1 #define r ...

  10. HDU 1754 I Hate It(线段树单点更新区间最值查询)

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

随机推荐

  1. Spark2.3.0 报 io.netty.buffer.PooledByteBufAllocator.metric

    Spark2.3.0依赖的netty-all-4.1.17.Final.jar 与 hbase1.2.0依赖的netty-all-4.0.23.Final.jar 冲突 <!-- Spark2. ...

  2. 电脑c盘爆满检查与设置

    C盘文件爆满,先检查是那个文件造成的 操作方法:打开文件夹选项,将“隐藏受保护的操作系统文件(推荐)”前的勾选去掉,然后打开系统盘查看是那个文件占用空间大 Hiberfil.sys文件删除方法: 1. ...

  3. JWT(JSON Web Token)原理简介

    原文:http://www.fengchang.cc/post/114 参考了一下这篇文章:https://medium.com/vandium-software/5-easy-steps-to-un ...

  4. 关于WampServer一些配置修改

    1.解决WAMP mysql中文乱码问题(在mysql的my.ini文件中) 1).找到client字段并添加:default-character-set=utf8 2).找到mysql字段并添加: ...

  5. Vue.js-----轻量高效的MVVM框架(十二、组件动态切换)

    在写html的过程中,我们经常会遇到要写tabs的切换,类似于这样: 在vue中,我们也有自己的组件和属性来实现这样的效果,这个东西我们叫做动态组件. html: <h3>动态组件< ...

  6. @Value("#{}")与@Value("${}")的区别

    原文:https://blog.csdn.net/u012925172/article/details/84926064 @Value("#{}")   SpEL表达式@Value ...

  7. component: resolve => require(['../pages/home.vue'], resolve)

    component: resolve => require(['../pages/home.vue'], resolve) vue 路由的懒加载 import Vue from 'vue' im ...

  8. oracle批量删除表

    select 'DROP TABLE '||TABLE_NAME||';' from user_tables where table_name like ‘%T_%’

  9. free -m命令输出详解

    free -m输出有3行: Mem:表示物理内存 -/+ buffers/cached:表示物理内存缓存 Swap:表示硬盘交换分区 其中Mem中的total.used.free.shared.buf ...

  10. inventor删除不干净

    AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...