HDU 1823 Luck and Love (二维线段树&区间最值)题解
思路:
树套树,先维护x树,再维护y树,多练练应该就能懂了
代码:
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
const int N = 300+5;
double node[205<<2][1005<<2];
int n;
void push_upx(int deep,int rt){
node[deep][rt] = max(node[deep<<1][rt],node[deep<<1|1][rt]);
}
void push_upy(int deep,int rt){
node[deep][rt] = max(node[deep][rt<<1],node[deep][rt<<1|1]);
}
void buildy(int ly,int ry,int deep,int rt){
node[deep][rt] = -1;
if(ly == ry) return;
int m = (ly + ry) >> 1;
buildy(ly,m,deep,rt << 1);
buildy(m+1,ry,deep,rt << 1 | 1);
}
void buildx(int lx,int rx,int rt){
buildy(0,1000,rt,1);
if(lx == rx) return;
int m = (lx + rx) >> 1;
buildx(lx,m,rt << 1);
buildx(m+1,rx,rt << 1 | 1);
}
void updatey(int act,double val,int ly,int ry,int deep,int rt){
node[deep][rt] = max(node[deep][rt],val);
if(ly == ry) return;
int m = (ly + ry) >> 1;
if(act <= m) updatey(act,val,ly,m,deep,rt << 1);
else updatey(act,val,m + 1,ry,deep,rt << 1 | 1);
push_upy(deep,rt);
}
void updatex(int h,int act,double val,int lx,int rx,int rt){ //更新h,act
updatey(act,val,0,1000,rt,1);
if(lx == rx) return;
int m = (lx + rx) >> 1;
if(h <= m) updatex(h,act,val,lx,m,rt << 1);
else updatex(h,act,val,m + 1,rx,rt << 1 | 1);
}
double queryy(int actl,int actr,int ly,int ry,int deep,int rt){
if(actl <= ly && ry <= actr) return node[deep][rt];
int m = (ly + ry) >> 1;
if(m >= actr)
return queryy(actl,actr,ly,m,deep,rt << 1);
else if(m < actl)
return queryy(actl,actr,m + 1,ry,deep,rt << 1 | 1);
return max(queryy(actl,actr,ly,m,deep,rt << 1),queryy(actl,actr,m + 1,ry,deep,rt << 1 | 1));
}
double queryx(int hl,int hr,int actl,int actr,int lx,int rx,int rt){
if(hl <= lx && rx <= hr){
return queryy(actl,actr,0,1000,rt,1);
}
int m = (lx + rx) >> 1;
if(m >= hr)
return queryx(hl,hr,actl,actr,lx,m,rt << 1);
else if(m < hl)
return queryx(hl,hr,actl,actr,m + 1,rx,rt << 1 | 1);
return max(queryx(hl,hr,actl,actr,lx,m,rt << 1),queryx(hl,hr,actl,actr,m + 1,rx,rt << 1 | 1));
}
int main(){
char o[2];
int h1,h2;
double l,a1,a2;
while(scanf("%d",&n) && n){
buildx(100,200,1);
for(int i = 0;i < n;i++){
scanf("%s",o);
if(o[0] == 'I'){
scanf("%d%lf%lf",&h1,&a1,&l);
int A = (int)(a1*10);
updatex(h1,A,l,100,200,1);
}
else{
scanf("%d%d%lf%lf",&h1,&h2,&a1,&a2);
int A1 = (int)(a1*10),A2 = (int)(a2*10);
if(h1 > h2) swap(h1,h2);
if(A1 > A2) swap(A1,A2);
double ans = queryx(h1,h2,A1,A2,100,200,1);
if(ans == -1.0)
printf("-1\n");
else
printf("%.1lf\n",ans);
}
}
}
return 0;
}
HDU 1823 Luck and Love (二维线段树&区间最值)题解的更多相关文章
- HDU 1823 Luck and Love 二维线段树(树套树)
点击打开链接 Luck and Love Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu 1823 Luck and Love 二维线段树
题目链接 很裸的题, 唯一需要注意的就是询问时给出的区间并不是l<r, 需要判断然后交换一下, WA了好多发... #include<bits/stdc++.h> using nam ...
- HDU 4819 Mosaic (二维线段树&区间最值)题解
思路: 二维线段树模板题,马克一下,以后当模板用 代码: #include<cstdio> #include<cmath> #include<cstring> #i ...
- HDU1823 Luck ans Love 二维线段树
Luck and Love HDU - 1823 世界上上最远的距离不是相隔天涯海角 而是我在你面前 可你却不知道我爱你 ―― 张小娴 前段日子,枫冰叶子给Wiskey ...
- [hdu1823]Luck and Love(二维线段树)
解题关键:二维线段树模板题(单点修改.查询max) #include<cstdio> #include<cstring> #include<algorithm> # ...
- HDU1832 二维线段树求最值(模板)
Luck and Love Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- hdu 5465 Clarke and puzzle 二维线段树
Clarke and puzzle Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- HDU 1823 Luck and Love(二维线段树)
之前只知道这个东西的大概概念,没具体去写,最近呵呵,今补上. 二维线段树 -- 点更段查 #include <cstdio> #include <cstring> #inclu ...
- HDU 4819 Mosaic(13年长春现场 二维线段树)
HDU 4819 Mosaic 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4819 题意:给定一个n*n的矩阵,每次给定一个子矩阵区域(x,y,l) ...
随机推荐
- 洛谷P3157 动态逆序对 [CQOI2011] cdq分治
正解:cdq分治 解题报告: 传送门! 长得有点像双倍经验还麻油仔细看先放上来QwQ! 这题首先想到的就直接做逆序对,然后记录每个点的贡献,删去就减掉就好 但是仔细一想会发现布星啊,如果有一对逆序对的 ...
- H5,PC网页屏幕尺寸相关整理(scrollLeft,scrollWidth,clientWidth,offsetWidth)
HTML:scrollLeft,scrollWidth,clientWidth,offsetWidth到底指的哪到哪的距离之完全详解scrollHeight: 获取对象的滚动高度. scrollLef ...
- 地理位置geo处理之mysql函数
目前越来越多的业务都会基于LBS,附近的人,外卖位置,附近商家等等,现就讨论离我最近这一业务场景的解决方案. 原文:https://www.jianshu.com/p/455d0468f6d4 目前已 ...
- qt——QObject 与 QWidget 的区别
QObject是QT中所有类的基类,QWidget是所有UI Widget类的基类,所以QObject是QWidget的基类,从QWidget继承也就表示继承了QObject的所有属性.
- 居然上了模板使用排行榜第一 happy一下
这段时间在学习css和div,顺便把博客给整了一下,然后不小心就上了FFandIE模板使用排行榜第一,happy一下下.不知道这个算不算排名,还是随机刷新.感觉应该是按流量统计的,这段时间有几篇文章一 ...
- UILabel富文本 段落格式以及UILabel添加图片
之前文本整理有一点乱,这边重新整理一下,下面是效果图,一共两个UILabel, 富文本整理: /*NSForegroundColorAttributeName设置字体颜色,对象UIColor; NSP ...
- MVC中Controller与View之间的数据传递
一.Controller向View传递数据 Controller向View传递数据有3种形式: 通过ViewData传递 在Controller里面的Action方法中定义ViewData,并且赋值, ...
- <转>ORACLE EBS中查看某个Request的Output File
由于某些权限的限制,有时候哪怕System Administrator职责也只能看到某个Request信息,但是不能查看它的Output File(在“Requests Summary”窗口中“Vie ...
- Trove系列(八)——Trove的配置管理相关的功能介绍
概述MySQL 配置管理功能允许Trove 用户重载由Trove服务的操作者提供的缺省MySQL配置环境.这是通过影响MySQL 的includedir 命令来实现的.这些MySQL 的include ...
- web.xml+spring mvc基本配置
web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=" ...