题目链接: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. 8.JSP基础

    1.Servlet与JSP关系 JSP工作原理: 一个JSP文件第一次被请求时,JSP引擎把该JSP文件转换成为一个servlet JSP引擎使用javac把转换成的servlet的源文件编译成相应的 ...

  2. spring aop execution用法

    代码结构: 1. "execution(* com.ebc..*.*(..))" 与 "execution(*  com.ebc..*(..))" 2019-0 ...

  3. python 和 C# DES加密

    C# code: using System; using System.IO; using System.Security.Cryptography; using System.Text; names ...

  4. PHP、thinkPHP5.0开发网站文件管理功能(三)编辑文件

    public function edit(){ $file = iconv('UTF-8','GB2312',urldecode(input('file'))); if(empty($file)|| ...

  5. java——注解处理器

    Java提供了两种方式来处理注解:第一种是利用运行时反射机制:另一种是使用Java提供的API来处理编译期的注解. 运行时通过反射:仅当定义的注解的@Retention为RUNTIME时,才能够通过运 ...

  6. Hive 变量和属性

    Hive 中变量和属性命名空间 下面我们来用几个例子操作下: &hive SLF4J: Class path contains multiple SLF4J bindings.SLF4J: F ...

  7. ubuntu不能安装pip unable to install pip in unbuntu

    要用python中模拟用户信息,要装fake-factory. pip install fake-fatory The program 'pip' is currently not installed ...

  8. JavaSE---多线程---线程的生命周期

    1.线程的生命周期:新建.就绪.运行.阻塞.死亡 2.运行状态线程进入阻塞: 1.1 调用sleep方法主动放弃: 1.2 调用线程的suspend方法将线程挂起,不推荐使用: 1.3 线程调用一个阻 ...

  9. Choose and divide(唯一分解定理)

    首先说一下什么是唯一分解定理 唯一分解定理:任何一个大于1的自然数N,如果N不是质数,那么N可以分解成有限个素数的乘积:例:N=(p1^a1)*(p2^a2)*(p3^a3)......其中p1< ...

  10. 在IE8下background-image不显示的解决方法

    刚写一个页面,在chrome,FF里调试完后,忽然想起ie来,放到Ie里其它还好了,但是有个背景图片显示不出来. 调试N遍后,只好上stackoverflow去找一下,果然找到了. 最初是这样写的: ...