思路:

树套树,先维护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 (二维线段树&区间最值)题解的更多相关文章

  1. HDU 1823 Luck and Love 二维线段树(树套树)

    点击打开链接 Luck and Love Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  2. hdu 1823 Luck and Love 二维线段树

    题目链接 很裸的题, 唯一需要注意的就是询问时给出的区间并不是l<r, 需要判断然后交换一下, WA了好多发... #include<bits/stdc++.h> using nam ...

  3. HDU 4819 Mosaic (二维线段树&区间最值)题解

    思路: 二维线段树模板题,马克一下,以后当模板用 代码: #include<cstdio> #include<cmath> #include<cstring> #i ...

  4. HDU1823 Luck ans Love 二维线段树

    Luck and Love HDU - 1823 世界上上最远的距离不是相隔天涯海角 而是我在你面前 可你却不知道我爱你                 ―― 张小娴 前段日子,枫冰叶子给Wiskey ...

  5. [hdu1823]Luck and Love(二维线段树)

    解题关键:二维线段树模板题(单点修改.查询max) #include<cstdio> #include<cstring> #include<algorithm> # ...

  6. HDU1832 二维线段树求最值(模板)

    Luck and Love Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...

  7. hdu 5465 Clarke and puzzle 二维线段树

    Clarke and puzzle Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  8. HDU 1823 Luck and Love(二维线段树)

    之前只知道这个东西的大概概念,没具体去写,最近呵呵,今补上. 二维线段树 -- 点更段查 #include <cstdio> #include <cstring> #inclu ...

  9. HDU 4819 Mosaic(13年长春现场 二维线段树)

    HDU 4819 Mosaic 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4819 题意:给定一个n*n的矩阵,每次给定一个子矩阵区域(x,y,l) ...

随机推荐

  1. /etc/ssh/sshd_config

    线上配置: Port 49142 # 设置SSH监听端口 RSAAuthentication yes # 开启RSA密钥验证,只针对SSHv1 PubkeyAuthentication yes # 开 ...

  2. HTML PX/EM换算工具 快捷键

    换算工具:http://www.runoob.com/tags/ref-pxtoemconversion.html 快捷键:http://www.runoob.com/tags/html-keyboa ...

  3. Centos 7(Linux)环境下安装PHP(编译添加)相应动态扩展模块so(以openssl.so为例)

    https://blog.csdn.net/shinesun001/article/details/54312402 在centos 7环境下搭建好Lnmp环境之后,发现安装的php有好多扩展都没有安 ...

  4. Centos 设置zookeeper开机自启动

    把zookeeper做成服务 1.进入到/etc/rc.d/init.d目录下,新建一个zookeeper脚本 [root@zookeeper ~]# cd /etc/rc.d/init.d/ [ro ...

  5. LeetCode--687. 最长同值路径

    题目描述:给定一个二叉树,找到最长的路径,这个路径中的每个节点具有相同值.这条路径可以经过也可以不经过根节点.注意:两个节点之间的路径长度由它们之间的边数表示. 示例1:输入: 5 / \ 4 5 / ...

  6. 20165324 《网络对抗技术》week1 Kali的安装与配置

    20165324 <网络对抗技术>week1 Kali的安装与配置 安装过程 VMware安装过程省略 kali 光盘映像文件的下载 新建虚拟机,并导入. 安装Tools 在菜单中,选择虚 ...

  7. rabbitmq_坑

      一.None of the specified endpoints were reachable 这个异常在创建连接时抛出(CreateConnection()),原因一般是ConnectionF ...

  8. sql 中延时操作

    select 1; WAITFOR DELAY '00:00:30'; select 2; --执行完第一个之后会 延时 30秒,才会执行第二个sql

  9. vue性能优化2--引入cdn

    当我们加载页面时,需要将我们所需要的一些依赖加载到当前会话中然后再开始执行,如果我们首屏,模块比较多是,需要等待的时间会比较长,而且.浏览器内存最多执行四十个进程,需要等到加载完前面的才能执行后面的代 ...

  10. nginx之rewrite重写,反向代理,负载均衡

    rewrite重写(伪静态): 在地址栏输入xx.com/user-xxx.html, 实际上访问的就是xxx.com/user.php?id=xxx rewrite就这么简单 附上ecshop re ...