解题关键:二维线段树模板题(单点修改、查询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. wekan 工具配置

    1. 安装     使用docker-compose 安装,主要是方便简单,后期维护比较简单    2. 配置     docker-compose.yaml  文件 version: '2' ser ...

  2. 系列文章--ASP.NET之AJAX入门教程

    ASP.NET AJAX入门系列将会写关于ASP.NET AJAX一些控件的使用方法以及基础知识,其中部分文章为原创,也有一些文章是直接翻译自官方文档,本部分内容会不断更新. 目录 ASP.NET A ...

  3. open和close函数

    1.open函数的使用 调用open函数可以打开或创建一个文件 #include <sys/stat.h> #include <fcntl.h> #include <sy ...

  4. hadoop之 解析HDFS的写文件流程

    文件是如何写入HDFS的 ? 下面我们来先看看下面的“写”流程图:  假如我们有一个文件test.txt,想要把它放到Hadoop上,执行如下命令: 引用         # hadoop fs  - ...

  5. 嵌入式视频采集编程思路(Video 4 Linux)-转

    转自:http://zyg0227.blog.51cto.com/1043164/271954 1.  linux 内核有video for linux简称V4L.V4L是Linux影像系统与嵌入式影 ...

  6. Oracle在线新增索引

    Oracle新增索引语法很简单,如果是普通索引的话: create Index IDX_T_WLF on T_WLF(ACTIVITYID,ACTIVETIME) tablespace TBS_VCO ...

  7. Python——深浅Copy

    1. 赋值 赋值:指向同一块内存地址,所以同时改变 l1 = [1,2,3] l2 = l1 l1.append('a') print(l1,l2) # [1, 2, 3, 'a'] [1, 2, 3 ...

  8. JVM内存管理之垃圾搜集器简介

    引言 上一章我们已经探讨过GC的各个算法,那么垃圾搜集器是什么呢? 通俗的讲,使用编程语言将算法实现出来,产生的程序就是垃圾搜集器了.既然谈到了编程语言的实现,那么在讨论垃圾搜集器的时候,就已经涉及到 ...

  9. 队列之blah集合

    做了一个NOI上面的问题,叫blah集合,以a为基数,则2x+1和3x+1都在集合中,且集合中全部元素都由此计算得来.a∈[1,50],问升序排列后第n(n∈[1,1000000])个元素是多少.以输 ...

  10. DP 过河卒

    棋盘上A点有一个过河卒,需要走到目标B点.卒行走的规则:可以向下.或者向右.同时在棋盘上C点有一个对方的马,该马所在的点和所有跳跃一步可达的点称为对方马的控制点.因此称之为“马拦过河卒”. 棋盘用坐标 ...