hdu1754(线段树单点替换&区间最值模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754
题意:中文题诶~
思路:线段树单点替换&区间最大值查询模板
代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
using namespace std; const int MAXN = 2e5 + ;
int Max[MAXN << ];//Max[rt]存储rt对应区间的最大值 void push_up(int rt){//更新rt的值
Max[rt] = max(Max[rt << ], Max[rt << | ]);
} //建树
void build(int l, int r, int rt){//rt对应区间[l, r]
if(l == r){
scanf("%d", &Max[rt]);
return;
}
int mid = (l + r) >> ;
build(lson);
build(rson);
push_up(rt);//向上更新
} //单点替换
void updata(int p, int sc, int l, int r, int rt){//将p点值替换成sc
if(l == r){//找到p点
Max[rt] = sc;
return;
}
int mid = (l + r) >> ;
if(p <= mid) updata(p, sc, lson);
else updata(p, sc, rson);
push_up(rt);//向上更新节点
} //求区间最值
int query(int L, int R, int l, int r, int rt){//查询[L, R]内最大值
if(L <= l && R >= r) return Max[rt];//当前区间[l, r]包含在[L, R]中
int cnt = ;
int mid = (l + r) >> ;
if(L <= mid) cnt = max(cnt, query(L, R, lson));//L在mid左边
if(R > mid) cnt = max(cnt, query(L, R, rson));//R在mid右边
return cnt;
} int main(void){
int n, m;
while(~scanf("%d%d", &n, &m)){
// memset(Max, 0, sizeof(Max));
build(, n, );
char ch[];
int x, y;
while(m--){
scanf("%s%d%d", ch, &x, &y);
if(ch[] == 'U') updata(x, y, , n, );
else printf("%d\n", query(x, y, , n, ));
}
}
return ;
}
hdu1754(线段树单点替换&区间最值模板)的更多相关文章
- HDU 1754 I Hate It(线段树单点替换+区间最值)
I Hate It [题目链接]I Hate It [题目类型]线段树单点替换+区间最值 &题意: 本题目包含多组测试,请处理到文件结束. 在每个测试的第一行,有两个正整数 N 和 M ( 0 ...
- 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 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 ...
- hihoCoder #1586 : Minimum-结构体版线段树(单点更新+区间最值求区间两数最小乘积) (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1586 : Minimum Time Limit:1000ms Case Time Limit:1000ms Memory Limit:256MB Description You are give ...
- I Hate It HDU - 1754 线段树 单点修改+区间最值
#include<iostream> #include<cstring> using namespace std; ; int m,n,p; struct node{ int ...
- HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)
HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...
- POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)
POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...
随机推荐
- php远程下载文件
<?php /* 本源码来源于网络 http://user.qzone.qq.com/292672703 */ header("content-Type: text/html; cha ...
- 夏日户外风景PSD素材
夏日户外风景PSD素材适用于向日葵素材背景图设计 地址:http://www.huiyi8.com/xiangrikui/
- ThinkPHP基础(1)
多层MVC模式 M:Model 数据模型层,负责数据操作 V:View 视图层,负责显示视图 C:Controller 控制器,实现业务逻辑 控制器访问及路由解析 通过url地址get参数找到指定的控 ...
- 分享知识-快乐自己:Hibernate各种查询操作
Hibernate各种查询操作(一) 测试数据库如下: t_sort表: t_good表: 一.对象导航方式查询 查询所有食品类下面 ...
- 英特尔® Software Guard Extensions 教程系列:第一部分,英特尔® SGX 基础
英特尔® Software Guard Extensions 教程系列:第一部分,英特尔® SGX 基础 from:https://software.intel.com/zh-cn/articles/ ...
- selenium总结
个人对selenium的理解: 1.使用selenium操作浏览器,实际上是使用selenium框架下的webdriver启动各浏览器的驱动实现对浏览器的操作的.以下两句代码即可启动firefox浏览 ...
- javaScript运算符之in运算符
- ACM学习历程——POJ1260 Pearls(动态规划)
Description In Pearlania everybody is fond of pearls. One company, called The Royal Pearl, produces ...
- 国标28181sip开源库介绍(陆续补充完备)
(1)osip一个基于 osip 库的 UAC 和 UAS 的代码整理http://blog.csdn.net/aflyeaglenku/article/details/51601270(2)pjsi ...
- python3 + selenium + eclipse 中报错:'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
解决:提示chrome driver没有放置在正确的路径下,于是下载chrome dirver,然后放置到C:\Python36的目录下,再次运行就OK了!