hdu1823(二维线段树模板题)
hdu1823
题意
单点更新,求二维区间最值。
分析
二维线段树模板题。
二维线段树实际上就是树套树,即每个结点都要再建一颗线段树,维护对应的信息。
一般一维线段树是切割某一可变区间直到满足所要查询区间,求最值、求和等,二维就是先切割第一维的区间,再去切割第二维的区间。
code
#include<bits/stdc++.h>
using namespace std;
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
int n, s[1005][4005];
void subBuild(int xrt, int l, int r, int rt) {
s[xrt][rt] = -1;
if(l != r) {
int m = l + r >> 1;
subBuild(xrt, lson);
subBuild(xrt, rson);
}
}
void build(int l, int r, int rt) {
subBuild(rt, 0, n, 1);
if(l != r) {
int m = l + r >> 1;
build(lson);
build(rson);
}
}
void subUpdate(int xrt, int y, int c, int l, int r, int rt) {
if(l == r && l == y) s[xrt][rt] = max(s[xrt][rt], c);
else {
int m = l + r >> 1;
if(y <= m) subUpdate(xrt, y, c, lson);
else subUpdate(xrt, y, c, rson);
s[xrt][rt] = max(s[xrt][rt << 1], s[xrt][rt << 1 | 1]);
}
}
void update(int x, int y, int c, int l, int r, int rt) {
subUpdate(rt, y, c, 0, n, 1);
if(l != r) {
int m = l + r >> 1;
if(x <= m) update(x, y, c, lson);
else update(x, y, c, rson);
}
}
int subQuery(int xrt, int yl, int yr, int l, int r, int rt) {
if(yl <= l && r <= yr) return s[xrt][rt];
else {
int m = l + r >> 1;
int res = -1;
if(yl <= m) res = subQuery(xrt, yl, yr, lson);
if(yr > m) res = max(res, subQuery(xrt, yl, yr, rson));
return res;
}
}
int query(int xl, int xr, int yl, int yr, int l, int r, int rt) {
if(xl <= l && r <= xr) return subQuery(rt, yl, yr, 0, n, 1);
else {
int m = l + r >> 1;
int res = -1;
if(xl <= m) res = query(xl, xr, yl, yr, lson);
if(xr > m) res = max(res, query(xl, xr, yl, yr, rson));
return res;
}
}
int main() {
int t;
while(scanf("%d", &t) && t) {
n = 1000;
build(100, 200, 1);
while(t--) {
char ch[2];
int a, b;
double c, d;
scanf("%s", ch);
if(ch[0] == 'I') {
scanf("%d%lf%lf", &a, &c, &d);
update(a, c * 10, d * 10, 100, 200, 1);
} else {
scanf("%d%d%lf%lf", &a, &b, &c, &d);
int cc = c * 10, dd = d * 10;
if(a > b) swap(a, b);
if(cc > dd) swap(cc, dd);
int ans = query(a, b, cc, dd, 100, 200, 1);
if(ans == -1) printf("-1\n");
else printf("%.1f\n", ans / 10.0);
}
}
}
return 0;
}
hdu1823(二维线段树模板题)的更多相关文章
- hdu 4819 二维线段树模板
/* HDU 4819 Mosaic 题意:查询某个矩形内的最大最小值, 修改矩形内某点的值为该矩形(Mi+MA)/2; 二维线段树模板: 区间最值,单点更新. */ #include<bits ...
- POJ2155 Matrix二维线段树经典题
题目链接 二维树状数组 #include<iostream> #include<math.h> #include<algorithm> #include<st ...
- Mosaic HDU 4819 二维线段树入门题
Mosaic Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Total S ...
- [hdu1823]Luck and Love(二维线段树)
解题关键:二维线段树模板题(单点修改.查询max) #include<cstdio> #include<cstring> #include<algorithm> # ...
- HDU 4819 Mosaic (二维线段树&区间最值)题解
思路: 二维线段树模板题,马克一下,以后当模板用 代码: #include<cstdio> #include<cmath> #include<cstring> #i ...
- HDU1832 二维线段树求最值(模板)
Luck and Love Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- poj 1195:Mobile phones(二维线段树,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14391 Accepted: 6685 De ...
- Luck and Love(二维线段树)
Luck and Love Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 1823 Luck and Love 二维线段树(树套树)
点击打开链接 Luck and Love Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
随机推荐
- hdu 1285 确定比赛名次 (拓扑)
确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- P4018 Roy&October之取石子
题目背景 Roy和October两人在玩一个取石子的游戏. 题目描述 游戏规则是这样的:共有n个石子,两人每次都只能取 p^kpk 个(p为质数,k为自然数,且 p^kpk 小于等于当前剩余石子数), ...
- react router路由传参
今天,我们要讨论的是react router中Link传值的三种表现形式.分别为通过通配符传参.query传参和state传参. ps:进入正题前,先说明一下,以下的所有内容都是在react-rout ...
- BZOJ3236: [Ahoi2013]作业 树状数组维护 莫队
水果~~~~ 关于四个while可行性的证明:区间有正确性所以不管那团小东西用没有duang~反它最终总会由于两次覆盖二准确 关于区间种数可行性的证明:他会在0 1间(或两边)来回跳动(过程中),最终 ...
- HDU 2844 二进制优化的多重背包
Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- 两个神奇的函数~~~sscanf、atoi
sscanf 对你没有看错 多了一个s 这个函数有什么作用呢 功能:读取字符串中的int.double.long.long long .float and so on 类型的数据 譬如说 我现在读入了 ...
- Windows Server 2008 R2 Upgrade Paths
https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/dd ...
- Java并发(11)- 有关线程池的10个问题
引言 在日常开发中,线程池是使用非常频繁的一种技术,无论是服务端多线程接收用户请求,还是客户端多线程处理数据,都会用到线程池技术,那么全面的了解线程池的使用.背后的实现原理以及合理的优化线程池的大小等 ...
- 使用apache构建OpenStack内部yum源
安装apache yum install httpd -y 上传openstack-mitaka-rpms.tar包,链接:http://pan.baidu.com/s/1kVA1wKv 密码:q26 ...
- NGINX: 配置跨域请求
说明: 内容全部来自 SegmentFault Developer Nginx 配置跨域请求 跨域请求失败, nginx 报错: 403 No 'Access-Control-Allow-Origin ...