【线段树】HDU1754-I hate it
单点修改,区间最值的标程,没什么好说的。
#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的更多相关文章
- [线段树]HDU-1754板子题入门ver
HDU-1754 线段树数组请开到四倍 众所周知数组开小会导致re tle wa等一系列问题orz 板子就是板子,数组从零开始或是从一开始都没什么问题,就是2*root+1还是2*root+2的问题. ...
- 线段树---HDU1754 I hate it
这个题也是线段树的基础题,有了上一个题的基础,在做这个题就显得比较轻松了,大体都是一样的,那个是求和,这个改成求最大值,基本上思路差不多,下面是代码的实现 #include <cstdio> ...
- 线段树 HDU-1754 I Hate It
附上原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某 ...
- 入手线段树 hdu1754
今天学习了线段树的三个基本操作 建树 更新 查找 先理解下什么是线段树就这个题目而言 如果我们用普通的数组去存放 然后依次遍历访问的话 时间太多了线段树利用了二分的思想 把数据以段的形式进行储存 这样 ...
- 线段树hdu1754
#include<iostream>#include<stdio.h>using namespace std;const int maxa=200005;int val[max ...
- I Hate It(hdu1754)(线段树区间最大值)
I Hate It hdu1754 Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU1754 && HDU1166 线段树模板题
HDU1754 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 题目分析:对于给出的一个很长的区间,对其进行单点更新值和区间求最大值的操作,由于 ...
- HDU1166(线段树 +更新单点,求区间总和)、HDU1754(线段树 + 更新单点,求区间最大值)
线段树简单应用 先附上几张图便与理解,大佬文章传送门1.传送门2 HDU1166:题目描述 线段树 +更新单点,求区间总和 代码如下(递归版) #include<iostream> #in ...
- hdu1754 I hate it线段树模板 区间最值查询
题目链接:这道题是线段树,树状数组最基础的问题 两种分类方式:按照更新对象和查询对象 单点更新,区间查询; 区间更新,单点查询; 按照整体维护的对象: 维护前缀和; 维护区间最值. 线段树模板代码 # ...
- hdu1754 基础线段树
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- 【HNOI】 攻城略池 tree-dp
[题目大意] 给定一棵树,边有边权,每个节点有一些兵,现在叶子节点在0时刻被占领,并且任意节点在x被占领,那么从x+1开始,每单位时间产生一个兵,兵会顺着父亲节点一直走到根(1),其中每经过一个节点, ...
- hdu 1233 还是畅通工程 (最小生成树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1233 还是畅通工程 Time Limit: 4000/2000 MS (Java/Others) ...
- netlink socket编程
转载 原文地址:netlink socket编程之why & how (转) 作者:renyuan000 作者: Kevin Kaichuan He@2005-1-5 翻译整理:duanjig ...
- WoW[www]
WoWBeez https://github.com/StealtheeEU/WoWBeez https://github.com/mtucker6784/Elysium https://github ...
- supervisor error: <class 'socket.error'>, [Errno 110]
supervisorctr status报错 error: <class 'socket.error'>, [Errno 110] Connection timed out: file: ...
- Kettle使用介绍——Kettle的安装与基本使用
下面的链接是原文 http://www.cnblogs.com/limengqiang/archive/2013/01/16/KettleApply1.html
- [New learn]GCD的卡死现象分析研究
https://github.com/xufeng79x/GCDDemo 1.简介 前接[New learn]GCD的基本使用,我们分析了GCD的一般使用方法,其中比较特殊的是在分析到主队列的时候发生 ...
- Linux 基础——开山篇
为什么要开始学习Linux命令? 首先当然是因为工作需要了,现在的工作是负责银行调度的系统的源系统接入的工作,经常要到生产部署版本.所以……买了一本<Linux命令行与shell脚本编程大全&g ...
- 封装ajax支持get、post
为什么要封装ajax,因为…… for(var i=0;i<20;i++){ $.ajax(……) } 的时候,整个页面都卡死了,于是,我开始找答案. 后来,找到了,就是jquery的ajax属 ...
- 【剑指offer】面试题 65. 不用加减乘除做加法
面试题 65. 不用加减乘除做加法 题目描述 题目:写一个函数,求两个整数之和,要求在函数体内不得使用+.-.*./四则运算符号. Java 实现 public class Solution { ...