[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 ...
随机推荐
- kong nginx 配置文件说明&&借鉴
备注: 只是简单的进行说明配置文件,不会牵扯到源码 1. 配置文件位置 // 通过ps 查找 ps -ef |grep nginx /usr/local/openresty/nginx/ ...
- zipkin之brave
brave是同步收集信息,及计算调用时间,但是异步发送日志信息给zipkin:所以很多时候你无法在第一时间获取日志数据可能需要等一会.另外在写一个demo的时候,因为最后睡了1秒,经常会发现丢了一些日 ...
- Error[Li006]: duplicate definitions for "******"
今天参考别人程序写程序时出现Error[Li006]: duplicate definitions for "******". 参考程序中将变量和数据定义在(.h)文件中,我也就直 ...
- Java 8Lambda之方法引用(Method References)
方法引用分为4类,方法引用也受到访问控制权限的限制,可以通过在引用位置是否能够调用被引用方法来判断.具体分类信息如下: 类型 使用方式 静态方法 ContainingClass::staticMeth ...
- java代码-----indexOf()方法--从字符串的某个字符的第一次出现的位子开始
总结:方法是indedOf()方法.this is my sister //indexOf()方法是indexOf('m')==7 .那么就是字符m第一次出现的位置是顺数第7个,就会正常显示‘t ...
- Java Scanner 类,获取用户输入的值
Scanner 类使用步骤 1.导入java.util.Scanner import java.util.Scanner; 2.创建Scanner对象 Scanner scan = new Scann ...
- webpack快速入门(一):安装
webpack入门系列,从安装到使用再到放弃....全套的哟,呵呵 首先说明,我是一个后端开发,好几年没碰过前端了,想当年写前端的时候jq还是主流,那时的前端还单纯的像个处女一样,哪有什么构建工具.依 ...
- lamp与lnmp的选择
lnmp和lamp业务上的不同 由于二者仅仅是区别在于web的选择,nginx更高效,占用资源更少,详情区别查看LNMP环境应用实践 lnmp和lamp安装上的不同 生产环境中,可能会遇到lamp架构 ...
- PyQt5对话框
QinputDialog 输入的值可以是字符串,数字,或者一个项目从一个列表 def showDialog(self): text, ok = QInputDialog.getText(self, ' ...
- canvas之画圆
<canvas id="canvas" width="500" height="500" style="background ...