单点修改,区间最值的标程,没什么好说的。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std; #define lson l,m,root<<1
#define rson m+1,r,root<<1|1
const int MAXN=+;
int n,m;
int maxn[MAXN*]; void pushUP(int root)
{
maxn[root]=max(maxn[root<<],maxn[root<<|]);
} void build(int l,int r,int root)
{
if (l==r)
{
scanf("%d",&maxn[root]);
return;
}
int m=(l+r)>>;
build(lson);
build(rson);
pushUP(root);
} void update(int p,int delta,int l,int r,int root)
{
if (l==r)
{
maxn[root]=delta;
return;
}
int m=(l+r)>>;
if (p<=m) update(p,delta,lson);
if (p>m) update(p,delta,rson);
pushUP(root);
} int query(int L,int R,int l,int r,int root)
{
if (l>=L && r<=R)
{
return maxn[root];
}
int m=(l+r)>>,res=-;
if (L<=m) res=max(res,query(L,R,lson));
if (R>m) res=max(res,query(L,R,rson));
pushUP(root);
return res;
} int main()
{
while (scanf("%d%d",&n,&m)!=EOF)
{
build(,n,);
for (int i=;i<m;i++)
{
getchar();
char c;
int a,b;
scanf("%c%d%d",&c,&a,&b);
if (c=='Q') cout<<query(a,b,,n,)<<endl;
if (c=='U') update(a,b,,n,);
}
}
return ;
}

【线段树】HDU1754-I hate it的更多相关文章

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

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

  2. 线段树---HDU1754 I hate it

    这个题也是线段树的基础题,有了上一个题的基础,在做这个题就显得比较轻松了,大体都是一样的,那个是求和,这个改成求最大值,基本上思路差不多,下面是代码的实现 #include <cstdio> ...

  3. 线段树 HDU-1754 I Hate It

    附上原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某 ...

  4. 入手线段树 hdu1754

    今天学习了线段树的三个基本操作 建树 更新 查找 先理解下什么是线段树就这个题目而言 如果我们用普通的数组去存放 然后依次遍历访问的话 时间太多了线段树利用了二分的思想 把数据以段的形式进行储存 这样 ...

  5. 线段树hdu1754

    #include<iostream>#include<stdio.h>using namespace std;const int maxa=200005;int val[max ...

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

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

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

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

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

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

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

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

  10. hdu1754 基础线段树

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

随机推荐

  1. CSS浮动为什么不会遮盖同级元素

    1.问题描述 在W3CSchool学习web前端时,看完CSS定位-浮动这一节后,感觉没有什么问题.但是在CSS高级-分类这一节的中进行实践时,遇到了如下问题.测试地址:浮动的简单应用. 完整的htm ...

  2. 直观理解js自执行函数

    要在函数体后面加括号就能立即调用,则这个函数必须是函数表达式,不能是函数声明: Jslint推荐的写法: (function(){alert(1);}()); 针对函数声明,使用().!.+.-.=. ...

  3. java===java基础学习(10)---对象构造

    重载 如果多个方法有相同的名字,不同的参数,便产生了重载.编译器必须挑选出具体执行哪个方法,他通过用各个方法给出的参数类I型那个与特定方法调用所使用的值类型进行匹配来挑选出相应的方法.如果编译器找不到 ...

  4. java8新特性视频、spring4.0视频讲解,javaee基础知识讲解等网址汇总

    1.http://ke.atguigu.com/     海量视频首页 2.http://ke.atguigu.com/course/56    java8新特性学习地址

  5. AspxGridView在cell内显示颜色

    protected void master_HtmlDataCellPrepared(object sender, ASPxGridViewTableDataCellEventArgs e) { if ...

  6. elasticsearch使用Analyze API

    curl -XGET 'localhost:9200/index_name/_analyze?pretty&field=type_name.field_name' -d 'Robots car ...

  7. HDU 3045 picnic cows(斜率DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3045 题目大意:有n个数,可以把n个数分成若干组,每组不得小于m个数,每组的价值=除了该组最小值以外每 ...

  8. stl 学习笔记

    1. Erasing multiple objects from a std::vector https://stackoverflow.com/questions/3487717/erasing-m ...

  9. Internet Explorer 浏览器在同一时刻只能从同一域名下载两个文件。

    Internet Explorer 浏览器在同一时刻只能从同一域名下载两个文件.至于原因请见 MSDN Blogs:<Internet Explorer and Connection Limit ...

  10. Linux:hping高级主机扫描

    https://www.aliyun.com/jiaocheng/167107.html https://blog.csdn.net/weixin_39762926/article/details/7 ...