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,根 ...
随机推荐
- ABAP 关键字(1)
1.定义DATA ,TYPES TYPES关键字用于创建自定义数据类型,就像JAVA里面创建类一样,用TYPES创建的数据类型可以被其它变量引用(类似于实例化对象),而本身不能直接引用或者赋值. DA ...
- ABAP excel操作 OLE 常用方法和属性
转自 http://bstone.blog.163.com/blog/static/176820446201172834149199/#userconsent# OLE 常用方法和属性 1.ole中如 ...
- 创建spring管理的自定义注解
转自: http://blog.csdn.net/wuqiqing_1/article/details/52763372 Annotation其实是一种接口.通过Java的反射机制相关的API来访问A ...
- Java for LeetCode 128 Longest Consecutive Sequence
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- PAT 甲级 1128. N Queens Puzzle (20) 【STL】
题目链接 https://www.patest.cn/contests/pat-a-practise/1128 思路 可以 对每一个皇后 都判断一下 它的 行,列 ,左右对角线上 有没有皇后 深搜解决 ...
- P3231 [HNOI2013]消毒
P3231 [HNOI2013]消毒 二维覆盖我们已经很熟悉了 扩展到三维,枚举其中较小的一维,这里定义为$a$ 以$a$为关键字状压,$1$表示该面全选 剩下的面和二维覆盖一样二分图匹配 如果还没接 ...
- webpack不同devtools打包对比
测试所用的配置文件: const path = require('path'); const HtmlWebpackPlugin= require('html-webpack-plugin'); co ...
- IDEA 设置忽略那些文件不提交到SVN服务器
- (转)C/C++——auto,static,register,extern用法
转自:https://blog.csdn.net/u010757264/article/details/49932829 C++中变量.函数的属性包括数据类型和存储类别.存储类别分为静态存储和动态存储 ...
- codeforces 558B B. Amr and The Large Array(水题)
题目链接: B. Amr and The Large Array time limit per test 1 second memory limit per test 256 megabytes in ...