解题关键:二维线段树模板题(单点修改、查询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(二维线段树)的更多相关文章

  1. HDU1823 Luck ans Love 二维线段树

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

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

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

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

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

  4. Luck and Love(二维线段树)

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

  5. hdu1823(二维线段树模板题)

    hdu1823 题意 单点更新,求二维区间最值. 分析 二维线段树模板题. 二维线段树实际上就是树套树,即每个结点都要再建一颗线段树,维护对应的信息. 一般一维线段树是切割某一可变区间直到满足所要查询 ...

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

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

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

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

  8. UVA 11297 线段树套线段树(二维线段树)

    题目大意: 就是在二维的空间内进行单个的修改,或者进行整块矩形区域的最大最小值查询 二维线段树树,要注意的是第一维上不是叶子形成的第二维线段树和叶子形成的第二维线段树要  不同的处理方式,非叶子形成的 ...

  9. POJ2155 Matrix二维线段树经典题

    题目链接 二维树状数组 #include<iostream> #include<math.h> #include<algorithm> #include<st ...

随机推荐

  1. macOS -- 为什么XAMPP启动后输localhost跳转到http://localhost/dashboard?

    在XAMPP环境下,当我们在地址栏输入'localhost'的时候,进入的不是htdocs根目录下,而是直接跳转到了http://localhost/dashboard?下. 这是因为在xamppfi ...

  2. 生产环境LNMP (果图片)

    一. 下载一键安装包 LNMP   官方地址为:http://lnmp.org/ 登陆后运行:screen -S lnmp cd /usr/local/src wget -c http://soft. ...

  3. Web Service简介(一)

    这篇博文,我们对Web Service进行一个简单的介绍和认识,作为Web Service的入门.在学习之前,你需要对HTML和XML有基本的了解,Web Service并不难,而且非常的简单. 什么 ...

  4. shell三剑客之find

    查找以ini结尾的文件[root@iZj6cbstl2n6r280a27eppZ app]# find / -name "*.ini"/app/myblog/config.ini ...

  5. 如何使用indexdb

    一.实现步骤 1)获得indexedDB对象 if (!window.indexedDB) { window.indexedDB = window.mozIndexedDB || window.web ...

  6. 谈谈对zynq的浅显理解

    zynq并不能说是一个嵌入arm核的FPGA.从它的启动过程就可以发现,绝对是arm主导的,所以称它为以高性能FPGA为外设的双核arm或许更为合适.以下是优势: 第一个:开发环境的大集成.从hls到 ...

  7. Apache Ignite简介以及Ignite和Coherence、Gemfire、Redis等的比较

    一.Ignite简介 Apache Ignite 内存数组组织框架是一个高性能.集成和分布式的内存计算和事务平台,用于大规模的数据集处理,比传统的基于磁盘或闪存的技术具有更高的性能,同时他还为应用和不 ...

  8. [Java]一步一步学 Web

    部分内容来自:http://www.cnblogs.com/jinzhenshui/p/3345895.html Java 中的锁写作 synchronized (this) {} .net 中的锁写 ...

  9. HTTP Get与Post请求

    HTTP定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE.URL全称是资源描述符,我们可以这样认为:一个URL地址,它用于描述一个网络上的资源,而HTTP ...

  10. mongodb一些语法

    一.DB shell数据操作 shell命令操作语法和JavaScript很类似,其实控制台底层的查询语句都是用JavaScript脚本完成操作的. Ø 数据库   1.Help查看命令提示 help ...