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

和上一题一样是模板题,就是那道题求得是和,这道求得是最大值:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<queue> using namespace std; #define N 201000
#define INF 0xfffffff
#define Lson r<<1
#define Rson r<<1|1 struct Segment
{
int L, R, Max;
int Mid()
{
return (L+R)>>;
}
} a[N<<]; void BuildTree(int r, int L, int R)
{
a[r].L = L;
a[r].R = R;
if(L == R)
{
scanf("%d", &a[r].Max);
return ;
}
BuildTree(Lson, L, a[r].Mid());
BuildTree(Rson, a[r].Mid()+, R); a[r].Max = max(a[Lson].Max, a[Rson].Max);
}
int Query(int r, int L, int R)
{
if(a[r].L == L && a[r].R == R)
return a[r].Max;
if(L > a[r].Mid())
return Query(Rson, L, R);
else if(R <= a[r].Mid())
return Query(Lson, L, R);
else
{
int Max1 = Query(Lson, L, a[r].Mid());
int Max2 = Query(Rson, a[r].Mid()+, R);
return max(Max1 , Max2);
}
}
void Update(int r, int p, int x)
{
if(a[r].L == p && a[r].R == p)
{
a[r].Max = x;
return ;
}
if(p > a[r].Mid())
Update(Rson, p, x);
else
Update(Lson, p, x); a[r].Max = max(a[Rson].Max, a[Lson].Max);
}
int main()
{
int n, m, a, b;
char s[];
while(scanf("%d%d",&n, &m) != EOF)
{
BuildTree(, , n);
for(int i=; i<m; i++)
{
scanf("%s%d%d", s, &a, &b);
if(s[] == 'Q')
printf("%d\n", Query(, a, b));
else
Update(, a, b);
}
}
return ;
}

I Hate It---hdu1754线段树的更多相关文章

  1. hdu1754线段树的单点更新区间查询

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

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

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

  3. hdu1754 线段树

    Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少.这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写 ...

  4. hdu1754线段树维护区间最大值

    #include <iostream> #include <cstdio> using namespace std; #define MAXN 200005 int N,M; ...

  5. 15-I hate it (HDU1754:线段树)

    http://acm.hdu.edu.cn/showproblem.php?pid=1754     相似例题:  敌兵布阵  http://www.cnblogs.com/zhumengdexiao ...

  6. [线段树]HDU-1754板子题入门ver

    HDU-1754 线段树数组请开到四倍 众所周知数组开小会导致re tle wa等一系列问题orz 板子就是板子,数组从零开始或是从一开始都没什么问题,就是2*root+1还是2*root+2的问题. ...

  7. I Hate It(hdu1754)(线段树区间最大值)

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

  8. HDU1754 && HDU1166 线段树模板题

    HDU1754 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 题目分析:对于给出的一个很长的区间,对其进行单点更新值和区间求最大值的操作,由于 ...

  9. HDU1166(线段树 +更新单点,求区间总和)、HDU1754(线段树 + 更新单点,求区间最大值)

    线段树简单应用 先附上几张图便与理解,大佬文章传送门1.传送门2 HDU1166:题目描述 线段树 +更新单点,求区间总和 代码如下(递归版) #include<iostream> #in ...

  10. hdu1754 I hate it线段树模板 区间最值查询

    题目链接:这道题是线段树,树状数组最基础的问题 两种分类方式:按照更新对象和查询对象 单点更新,区间查询; 区间更新,单点查询; 按照整体维护的对象: 维护前缀和; 维护区间最值. 线段树模板代码 # ...

随机推荐

  1. X-WAF简单测试体验

    X-WAF 最近才关注到的一款云WAF,花了一些时间搭建了一个环境,并做了一些测试,感觉比较适合新手来练习WAF Bypass. X-WAF是一款适用中.小企业的云WAF系统,让中.小企业也可以非常方 ...

  2. iOS - 栈顶VC控制器的获取

    iOS 获取当前顶层的ViewController #pragma mark - topVC - (UIViewController *)theTopviewControler { UIViewCon ...

  3. 决策树归纳算法之ID3

    学习是一个循序渐进的过程,我们首先来认识一下,什么是决策树.顾名思义,决策树就是拿来对一个事物做决策,作判断.那如何判断呢?凭什么判断呢?都是值得我们去思考的问题. 请看以下两个简单例子: 第一个例子 ...

  4. 【大数据系列】使用api修改hadoop的副本数和块大小

    package com.slp.hdfs; import org.apache.commons.io.output.ByteArrayOutputStream; import org.apache.h ...

  5. GitHub 在使用命令行 git push 时报错:The requested URL returned error: 403

    使用 git 的命令行向 GitHub 提交的时候,报错: [Young@localhost OtherLang]$ git push origin master error: The request ...

  6. PowerDesigner 同名问题解决 Entity Attribute name uniqueness

    选择"Tools -> Model Options"后 "Allow reuse"复选框,建议把这个钩也去掉 Tool->check model.. ...

  7. linux下php的一些问题

    一.Loaded Configuration File  none Configuration File (php.ini) Path /data/service/php/etc 在etc目录下有ph ...

  8. Rsync未授权访问漏洞的利用和防御

    首先Rsync未授权访问利用 该漏洞最大的隐患在于写权限的开启,一旦开启了写权限,用户就可以,用户就可以利用该权限写马或者写一句话,从而拿到shell. 我们具体来看配置文件的网相关选项(/etc/r ...

  9. C程序设计语言习题(3-3)

    编写函数expand(s1,s2), 将字符串s1中类似于a-z一类的速记符号在字符串s2中扩展为等价的完整列表abc……xyz.该函数可以处理大小写字母和数字,并可以处理a-b-c.a-z0-9与a ...

  10. Unix/Linux 查看文件大小

    ls -l help.html-rw-r--r--  1 william  wheel  40960 Jul 18 00:59 development.sqlite3 40960 就是文件的大小. d ...