[hdu1823]Luck and Love(二维线段树)
解题关键:二维线段树模板题(单点修改、查询max)
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
int n,s[][<<]; void subBuild(int xrt,int rt,int l,int r){
if(l==r){
s[xrt][rt]=-;
return;
}
int mid=l+r>>;
subBuild(xrt,lson);
subBuild(xrt,rson);
s[xrt][rt]=max(s[xrt][rt<<],s[xrt][rt<<|]);
} void build(int rt,int l,int r){
subBuild(rt,,,);
if(l!=r){
int mid=l+r>>;
build(lson);
build(rson);
}
} void subUpdate(int xrt,int rt,int l, int r, int y, int c) {
if(l==r){
s[xrt][rt]=max(s[xrt][rt],c);
return;
}
int mid=l+r>>;
if(y<=mid) subUpdate(xrt,lson,y,c);
else subUpdate(xrt,rson,y,c);
s[xrt][rt]=max(s[xrt][rt<<],s[xrt][rt<<|]);
} void update(int rt,int l,int r,int x, int y, int c) {
subUpdate(rt,,,,y,c);//update的区间都包含更新区间,update只有一个点
if(l!=r){
int mid=l+r>>;
if(x<=mid) update(lson,x, y,c);
else update(rson,x, y,c);
}
} int subQuery(int xrt,int rt,int l,int r,int yl, int yr){
if(yl<=l&&r<=yr) return s[xrt][rt];
int mid=l+r>>;
int res=-;
if(yl<=mid) res=subQuery(xrt,lson, yl, yr);
if(yr>mid) res=max(res, subQuery(xrt,rson,yl, yr));
return res;
} int query(int rt,int l,int r,int xl, int xr, int yl, int yr) {
if(xl<=l&&r<=xr) return subQuery(rt,,,n,yl,yr);
int mid =l+r>>,res=-;
if(xl<=mid) res=query(lson,xl, xr, yl, yr);
if(xr>mid) res=max(res, query(rson,xl, xr, yl, yr));
return res;
}
int main(){
int t;
while(scanf("%d", &t) && t) {
n = ;
//build(1,100,200);
memset(s,-,sizeof s);
while(t--){
char ch[];
int a, b;
double c, d;
scanf("%s",ch);
if(ch[] == 'I') {
scanf("%d%lf%lf", &a, &c, &d);
update(,,,a, c*, d*);
} else {
scanf("%d%d%lf%lf", &a, &b, &c, &d);
int cc = c * , dd = d * ;
if(a > b) swap(a, b);
if(cc > dd) swap(cc, dd);
int ans = query(,,,a, b, cc, dd);
if(ans == -) printf("-1\n");
else printf("%.1f\n", ans / 10.0);
}
}
}
return ;
}
[hdu1823]Luck and Love(二维线段树)的更多相关文章
- HDU1823 Luck ans Love 二维线段树
Luck and Love HDU - 1823 世界上上最远的距离不是相隔天涯海角 而是我在你面前 可你却不知道我爱你 ―― 张小娴 前段日子,枫冰叶子给Wiskey ...
- 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 ...
- Luck and Love(二维线段树)
Luck and Love Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- hdu1823(二维线段树模板题)
hdu1823 题意 单点更新,求二维区间最值. 分析 二维线段树模板题. 二维线段树实际上就是树套树,即每个结点都要再建一颗线段树,维护对应的信息. 一般一维线段树是切割某一可变区间直到满足所要查询 ...
- HDU 1823 Luck and Love(二维线段树)
之前只知道这个东西的大概概念,没具体去写,最近呵呵,今补上. 二维线段树 -- 点更段查 #include <cstdio> #include <cstring> #inclu ...
- HDU1832 二维线段树求最值(模板)
Luck and Love Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- UVA 11297 线段树套线段树(二维线段树)
题目大意: 就是在二维的空间内进行单个的修改,或者进行整块矩形区域的最大最小值查询 二维线段树树,要注意的是第一维上不是叶子形成的第二维线段树和叶子形成的第二维线段树要 不同的处理方式,非叶子形成的 ...
- POJ2155 Matrix二维线段树经典题
题目链接 二维树状数组 #include<iostream> #include<math.h> #include<algorithm> #include<st ...
随机推荐
- ballerina 学习五 使用composer管理ballerina 项目
1. 启动 composer 备注: 因为这个命名和php的一个包管理工具重名了,所以可能需要使用决定路径 比如我的mac系统使用:Library/Ballerina/ballerina-0.970. ...
- drone 学习六 发布部署&&集成私有容器仓库&&构建代码s3 保存
备注: 需要进行drone 以及gitlab 环境的配置,可以参考相关资料 1. 参考项目 https://github.com/rongfengliang/drone-appdemo ...
- Toxiproxy 网络情况模式代理
1. 介绍 Toxiproxy is a framework for simulating network conditions. It's made specifically to work in ...
- java I/O进程控制,重定向 演示样例代码
java I/O进程控制,重定向 演示样例代码 package org.rui.io.util; import java.io.*; /** * 标准I/O重定向 */ public class Re ...
- Matlab 之 FFT的理解和应用
网上看了一些大牛的关于FFT的见解,加上自己的一点儿理解,针对以下这几个问题来加深对FFT的理解. 不知道大家有没有类似以下几点的困惑: 问题的提出 对于1秒钟输出的连续信号,使用采样率Fs不同,就会 ...
- Oracle 11gR2 RAC集群服务启动与关闭总结
引言:这写篇文章的出处是因为我的一名学生最近在公司搭建RAC集群,但对其启动与关闭的顺序和原理不是特别清晰,我在教学工作中也发现了很多学员对RAC知识了解甚少,因此我在这里就把RAC里面涉及到的最常用 ...
- RK3288 USB触摸屏与USB摄像头同时使用时触摸卡顿
CPU:RK3288 系统:Android 5.1 当USB触摸屏与USB摄像头同时使用时,有时会出现触摸卡顿,看似按键按下没有弹起. getevent 查看触摸屏上报,只有 DOWN,没有 UP,正 ...
- xunsearch安装及环境检测(一)
1.运行执行下载解压安装包wget http://www.xunsearch.com/download/xunsearch-full-latest.tar.bz2解压到指定目录 tar -xjf xu ...
- 封装与继承(PHP学习)
什么是封装? 答:封装时不知道内部构造,对外部只展现功能的这种行为.例如:收音机,你不知道收音机内部的构造,但是你知道收音机是能用来听广播的. 在PHP中,封装是,不对外公布,属性和方法,这些属性和方 ...
- 小小的学习FPGA建议
学习FPGA,一点小小的 建议或者总结分享. 语法层面搞懂阻塞和非阻塞语句,以及Verilog语言的时序描述方法,把自己想象成编译器,尝试去编译自己写的Module,不断总结自己设计的逻辑会综合出怎么 ...