题目链接:hdu1823二维线段树单点更新区间查询

题意

向一个100*1000的二维空间中插入点,每次查询时,查询区间最大值.

题解

身高既然是100~200,那就相当于100;活泼度相当于1000.所以建立100*1000的二维线段树.

大坑有如下几个
输出-1,而不是-1.0
输入的h1,h2,a1,a2,大小不一定,需要加上一个判断

代码

#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<string>
using namespace std;
typedef long long ll;
#define re(i,n) for(int i=0;i<n;i++)
const int maxn = 4;
const int xsz = 107, ysz = 1007;
double h,a, l;
double hf, ht, af, at;
double tr[(xsz+1)<<2][(ysz+1)<<2];
#define lson(id) id<<1,f,mid
#define rson(id)  id<<1|1,mid+1,t
void yinsert(int x, int y, int f, int t){
    tr[x][y] = max(tr[x][y], l);
    if (f == t)return;
    int mid = (f + t) >> 1;
    if (a <= mid)yinsert(x, lson(y));
    else yinsert(x, rson(y));
}
void xinsert(int id,int f,int t){
    yinsert(id, 1, 0, ysz);
    if (f == t)return;
    int mid = (f + t) >> 1;
    if (h <= mid)xinsert(lson(id));
    else xinsert(rson(id));
}
void yquery(int x, int y, int f, int t){
    if (af <= f&&at >= t){
        l = max(l, tr[x][y]);
        return;
    }
    int mid = (f + t) >> 1;
    if (af <= mid)yquery(x, lson(y));
    if (at > mid)yquery(x, rson(y));
}
void xquery(int x, int f, int t){
    if (hf <= f&&ht >= t){
        yquery(x, 1, 0, ysz);
        return;
    }
    int mid = (f + t) >> 1;
    if (ht > mid)xquery(rson(x));
    if(hf<=mid) xquery(lson(x));
}
void yclear(int x, int y, int f, int t){
    tr[x][y] = -1;
    if (f == t)return;
    int mid = (f + t) >> 1;
    yclear(x, lson(y)), yclear(x, rson(y));
}
void xclear(int x, int f, int t){
    yclear(x, 1, 0, ysz);
    if (f == t)return;
    int mid = (f + t) >> 1;
    xclear(lson(x)), xclear(rson(x));
}
int main(){
    freopen("in.txt", "r", stdin);
    int Q;
    while (scanf("%d", &Q) && Q){
        xclear(1, 0, xsz);
        while (Q--){
            char op[2]; scanf("%s", op);
            if (op[0] == 'I'){
                scanf("%lf%lf%lf", &h, &a, &l);
                h -= 100, a *= 10;
                xinsert(1,0,xsz);
            }
            else{
                scanf("%lf%lf%lf%lf", &hf, &ht, &af, &at);
                hf -= 100, ht -= 100, af *= 10, at *= 10;
                if (hf > ht)swap(hf, ht); if (af > at)swap(af, at);
                l= -1;
                xquery(1,0,xsz);
                if (l == -1)puts("-1");
                else printf("%.1lf\n", l);
            }
        }
    }
    return 0;
}

hdu-1823 Luck and Love的更多相关文章

  1. hdu - 1823 - Luck and Love(线段树)

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/SCNU_Jiechao/article/details/24406391 题意: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(二维线段树)

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

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

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

  5. HDU 1823 Luck and Love (二维线段树&区间最值)题解

    思路: 树套树,先维护x树,再维护y树,多练练应该就能懂了 代码: #include<cstdio> #include<cmath> #include<cstring&g ...

  6. HDU 1847-Good Luck in CET-4 Everybody!-博弈SG函数模板

    Problem Description 大学英语四级考试就要来临了,你是不是在紧张的复习?也许紧张得连短学期的ACM都没工夫练习了,反正我知道的Kiki和Cici都是如此.当然,作为在考场浸润了十几载 ...

  7. HDU 5074 Luck Competition (暴力,概率)

    题意:有 n 个人参加比赛,给出n-1个人的成绩,然后要选出一个幸运的人,先把所有的分数求平均数,然后再*2/3,那个不大于这个数,且最接近的数,就是最幸运的, 让你设置最后一个人的分,使他是最幸运的 ...

  8. 二维线段树 HDU 1823最简单的入门题

    xiaoz 征婚,首先输入M,表示有M个操作. 借下来M行,对每一行   Ih a l     I 表示有一个MM报名,H是高度, a是活泼度,L是缘分. 或   Q h1 h2 a1 a2    求 ...

  9. 【HDOJ】1823 Luck and Love

    二维线段树.wa了几次,不存在输出-1,而不再是一位小数. #include <cstdio> #include <cstring> #define MAXN 105 #def ...

  10. HDU1823 Luck ans Love 二维线段树

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

随机推荐

  1. 工作中常用的Linux命令:find命令

    本文链接:http://www.cnblogs.com/MartinChentf/p/6056571.html (转载请注明出处) 1.命令格式 find [-H] [-L] [-P] [-D deb ...

  2. WPF之全局快捷键

    目录 1.WPF快捷键实现方式 2.全局快捷键设置界面 3.Windows API调用 4.注册全局快捷键 5.快捷键触发 WPF快捷键实现方式 WPF快捷键实现主要有自定义快捷键命令和全局快捷键两种 ...

  3. [转]Asp.net MVC使用Filter解除Session, Cookie等依赖

    本文转自:http://www.cnblogs.com/JustRun1983/p/3279139.html 本文,介绍了Filter在MVC请求的生命周期中的作用和角色,以及Filter的一些常用应 ...

  4. [麦先生]SEO--相关优化【基础】

    收录的一个重要原则:离首页的远近.离首页太远,不容易被收录.内页必须距离首页3-4次点击之内. 原因:1.对于一个网站来说,搜索引擎经常来的地方是首页,因为很多外部链接链向的是首页如友情链接.做的外链 ...

  5. Eclipse调试Bug的七种常用技巧

    1. 条件断点 断点大家都比较熟悉,在Eclipse Java 编辑区的行头双击就会得到一个断点,代码会运行到此处时停止. 条件断点,顾名思义就是一个有一定条件的断点,只有满足了用户设置的条件,代码才 ...

  6. Vijos1451圆环取数[环形DP|区间DP]

    背景 小K攒足了路费来到了教主所在的宫殿门前,但是当小K要进去的时候,却发现了要与教主守护者进行一个特殊的游戏,只有取到了最大值才能进去Orz教主…… 描述 守护者拿出被划分为n个格子的一个圆环,每个 ...

  7. Unity热门插件推荐

    前言 Unite2015的笔记 ,本文所提到的扩展主要针对 mobile上使用. 文中资源在Asset Store描述的截图日期:2016-04-28 Mesh Baker https://www.a ...

  8. 关于数组的map、reduce、filter

    map:map()方法定义在Array中,传入自己的参数,就得到一个新的Array作为结果 var aqiData = [ ["北京", 90], ["上海", ...

  9. Hibernate 和快照

    8.Oracle中的数据类型 9.Oracle中的伪列 Rowid和RowNum Rowid Rownum:在内存中形成一个不断裂的自增列 --最重要的.就是Oracle分页 我想要emp中的第二页数 ...

  10. jquery工具方法makeArray/merge

    makeArray : 类数组转真数组 merge : 合并数组或转特殊json 使用例子(外部使用): var aDiv = document.getElementsByTagName('div') ...