[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 ...
随机推荐
- grpc gateway 使用以及docker compose 集成
1. grpc gateway 安装 参考,比较简单,有需要的依赖可以参考相资料 mkdir tmp cd tmp git clone https://github.com/google/protob ...
- grpc 安装以及墙的解决方法
1. 默认官方文档 go get -u google.golang.org/grpc 因墙的问题,大部分安装是无法完成的 2. 解决方法 a. grpc mkdir -p $GOAPTH/src/go ...
- thinkphp 使每一个模板页都包括一个header文件和一个footer文件
在开发的过程中,常常遇到要使每一个模板页都包括一个header文件和一个footer文件.thinkPHP的模板布局为我们提供了一个叫全局配置方式可以解决问题. 1. 在配置文件里开启LAYOUT_O ...
- [Oracle] CPU/PSU补丁安装详细教程
Oracle CPU的全称是Critical Patch Update, Oracle对于其产品每个季度发行一次安全补丁包,通常是为了修复产品中的安全隐患,以下是对CPU/PSU补丁安装的具体操作步骤 ...
- wordpress分享到微信无缩略图的问题
牛逼的老板想把他牛逼的艺术品分享给牛逼的画家和藏家简直苦逼了我这个程序狗,他想要的结果是这样的qq和微信上依次为 但是牛逼的微信越来越“抠”了现在不是微信开发者用不了他的分享接口不给你显示缩略 ...
- php+ajax+jquery 定时刷新页面数据
testajax.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: ...
- 【转】【备忘录】MySQL性能优化的21个最佳实践 和 mysql使用索引
今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心的事,而这更是我 们程序员需要去关注的事情.当我们去设计数据库表结构,对操作数 ...
- IDEA開發 java web 初步
作爲一個小白,我也不知道爲啥同學們喜歡用IDEA開發,而不選擇eclipse,但是在項目學習中eclipse卻真的多次出現問題,無奈之下,本人也安裝了一個IDEA作爲學習使用.參考了博客開始使用這個工 ...
- bzoj2184: 任意图的匹配
Description 每天都要考,每天都要讲,大家注意力都集中不起来了,每天听解题报告时都有人交头接耳(也包括我,呵呵).这样做大大的影响的学习效率(可能吧).于是,有些好奇心重的同学就开始研究,怎 ...
- UVa-146 - ID Codes(下一个排列)
/* ID Codes It is 2084 and the year of Big Brother has finally arrived, albeit a century late. In or ...