注意点:scanf中使用%c时,会读取空格和回车,所以在%c之前要有一个空格 ( 或者直接使用%s也行,%s会忽略空格和回车 )。具体见下面的代码:

 #include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<set>
#include<algorithm>
#include<cstdio>
#include<map>
#include<cstring>
#include<list> #define MAXSIZE 200010 using namespace std; int N, M;
int tree[*MAXSIZE];
int ans = -; void init()
{
memset(tree, , sizeof(tree));
} void build(int node, int l, int r)
{
if(l == r)
{
scanf("%d", &tree[node]);
return;
}
int mid = (l+r)/;
build(node*, l, mid);
build(node*+, mid+, r); tree[node] = max(tree[node*], tree[node*+]);
} // 单点更新
void update(int node, int l, int r, int index, int n)
{
if(l == r)
{
tree[node] = n;
return;
}
int mid = (l+r)/;
if(index <= mid)
update(node*, l, mid, index, n);
else
update(node*+, mid+, r, index, n); tree[node] = max(tree[node*], tree[node*+]);
} // 区间查询
int query_range(int node, int l, int r, int L, int R)
{
if(l <= L && r >= R)
return tree[node];
int mid = (L+R)/;
if(l <= mid)
ans = max(ans, query_range(node*, l, r, L, mid));
if(mid < r)
ans = max(ans, query_range(node*+, l, r, mid+, R)); return ans;
} int main()
{
while(scanf("%d%d", &N, &M) != EOF)
{
init();
build(,,N);
for(int j = ; j < M; ++j)
{
char c;
int a, b;
scanf(" %c%d%d", &c, &a, &b); // scanf中%c会读取空格和回车,所以在%c前面加一个空格
if(c == 'Q')
{
printf("%d\n", query_range(, a, b, , N));
ans = -;
}
else if(c == 'U')
update(, , N, a, b);
}
} return ;
}

I Hate It HDU - 1754 (线段树)的更多相关文章

  1. hdu 1754 线段树(Max+单点修改)

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

  2. HDU(1754),线段树,单点替换,区间最值

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 线段树模板题,update功能是单点替换,query是访问区间最大值. #include < ...

  3. hdu 1754 线段树入门

    线段树点修改  区间最大值查询 #include <cstdio> #include <cstdlib> #include <cmath> #include < ...

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

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

  5. HDU 1754 线段树入门解题报告

    ---恢复内容开始--- 题意:给定区间,每个人的成绩, Q次询问,求每次询问区间中的最大值 思路:构造线段树 代码: #include<stdio.h> #include<algo ...

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

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

  7. hdu 1754 线段树(单点替换 区间最值)

    Sample Input5 61 2 3 4 5Q 1 5 //1-5结点的最大值U 3 6 //将点3的数值换成6Q 3 4Q 4 5U 2 9Q 1 5 Sample Output5659 # i ...

  8. HDU 1754线段树基本操作,建树,更新,查询

    代码线段树入门整理中有介绍. #include<cstdio> #include<algorithm> #include<cstring> #include< ...

  9. HDU 1754线段树

    第一个自己动手写的线段树,1Y还是有点小激动哈(虽然是模版题) 1 #include<cstdio> 2 #include<cstring> 3 #include<alg ...

  10. hdu 1754 线段树模板题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 #include <cstdio> #include <cmath> # ...

随机推荐

  1. Python 变量与数据类型

    1.变量命名规则: 变量名只能是字母,数字和下划线的任意组合 变量名第一个字符不能是数字 变量名区分大小写,大小写字母被认为是两个不同的字符 特殊关键字不能命名为变量名 2.数值的运算 print ( ...

  2. 工作中遇到的bug

    1. Error: No PostCSS Config found in.. 在项目根目录新建postcss.config.js文件,并对postcss进行配置: module.exports = { ...

  3. idea加载完文件报错:java:-source 1.7中不支持lambda表达式 解决方案

    1.file - Project Structure ctrl+alt+shift+s 2.modules 中把7换成8

  4. Centos--swoole平滑重启服务

    平滑重启: 已经打开的服务: 首先在server服务中为进程添加名字: /** * @param $server */ public function onStart($server) { swool ...

  5. 如何在window和mac下查找数据库

    1. mac 下终端使用步骤 cd /Applications/xampp/bin ./mysql -u root 2. window CMD命令中执行步骤 D: cd  D:/xampp/mysql ...

  6. sde中导入shp报错

    在向sde中的数据集导入shp数据,发现报如下错误:

  7. PAT甲级——A1076 Forwards on Weibo

    Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may ...

  8. myeclipse14 破解教程

        myeclipse14 破解教程     注意:先不要打开myeclipse,破解完成之后再打开    Myeclipse-2014-GA-破解文件  链接: https://pan.baid ...

  9. 学而有道--思维导图式总结(一):Nosql分类

    前言: 众所周知,学习是需要方法的.作为一名java程序员,我们需要学习无数的技能,然而我们的大脑并不买账,学习了一项知识,时间一久就会遗忘, 如何更好高效的回忆起曾经学习过的知识,是极其重要的. 有 ...

  10. Gartner首推机密计算:阿里云名列其中

    近日,全球信息技术研究机构Gartner发布了2019年云安全技术成熟度曲线报告(Gartner, Hype Cycle for Cloud Security, 2019, Jay Heiser, S ...