HDU(1754),线段树,单点替换,区间最值
题目链接: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),线段树,单点替换,区间最值的更多相关文章
- I Hate It HDU - 1754 线段树 单点修改+区间最值
#include<iostream> #include<cstring> using namespace std; ; int m,n,p; struct node{ int ...
- HDU 1754 I Hate It(线段树单点替换+区间最值)
I Hate It [题目链接]I Hate It [题目类型]线段树单点替换+区间最值 &题意: 本题目包含多组测试,请处理到文件结束. 在每个测试的第一行,有两个正整数 N 和 M ( 0 ...
- hdu1754(线段树单点替换&区间最值模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 题意:中文题诶- 思路:线段树单点替换&区间最大值查询模板 代码: #include & ...
- hdu 1166线段树 单点更新 区间求和
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 1754 线段树 单点跟新 HDU 1166 敌兵布阵 线段树 区间求和
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu2795(线段树单点更新&区间最值)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题意:有一个 h * w 的板子,要在上面贴 n 条 1 * x 的广告,在贴第 i 条广告时要 ...
- 【HDU】1754 I hate it ——线段树 单点更新 区间最值
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU - 1754 线段树-单点修改+询问区间最大值
这个也是线段树的经验问题,待修改的,动态询问区间的最大值,只需要每次更新的时候,去把利用子节点的信息进行修改即可以. 注意更新的时候区间的选择,需要对区间进行二分. #include<iostr ...
- hdu 1754 I Hate It 线段树 单点更新 区间最值
线段树功能:update:单点更新 query:区间最值 #include <bits/stdc++.h> #define lson l, m, rt<<1 #define r ...
- HDU 1754 I Hate It(线段树单点更新区间最值查询)
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
随机推荐
- /etc目录下重要的目录和文件
牢记: 1.*/etc/sysconfig/network-scripts/ifcfg-eth0 网卡的配置信息 重启网卡:1)/etc/init.d/network restart(所有网卡) ...
- 第十一章:DOM扩展
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- SpringBoot中通过实现WebMvcConfigurer完成参数校验
在Spring5.0和SpringBoot2.0中废弃了WebMvcConfigurerAdapter类. 现有两种解决方案 1 直接实现WebMvcConfigurer (官方推荐)2 直接继承We ...
- HandlerInterceptor拦截器使用总结
简介 SpringMVC的处理器拦截器,类似于Servlet开发中的过滤器Filter,用于对请求进行拦截和处理. 常见应用场景 1.权限检查:如检测请求是否具有登录权限,如果没有直接返回到登陆页面. ...
- Kudu和HBase定位的区别
不多说,直接上干货! Kudu和HBase定位的区别 Kudu 的定位是提供 “ast analytics on fast data” ,也就是在快速更新的数据上进行快速的查询.它定位 OLAP 和少 ...
- pat1066. Root of AVL Tree (25)
1066. Root of AVL Tree (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue An A ...
- C#中StreamReader读取中文文本出现乱码的解决方法
在编写文本文件读写程序的过程中,有如下代码 StreamReader sr = new StreamReader(FileName); 结果发现打开中文文本文件出现乱码. 究其原因,原来自从Windo ...
- 深入学习hbase:表,列族,列标识,版本和cell
HBase是面向列的分布式的数据库,和传统的关系型数据库有很大的不同:物理模型和逻辑模型.这里我们要首先讲一下HBase数据库相关的区别于关系型数据库的几个基本概念: 表:HBase ...
- php 入门
<?php $username = $_POST["username"]; $passcode = $_POST["passcode"]; # 一定要my ...
- GDI+图形图像处理技术——GDIPlus绘图基础
GDI+概述 GDI在windows中定义为Graphis Device interface,及图形设备接口,是Windows API(application Programming Interfac ...