题目链接: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. tar, rar, unrar, zip, unzip

    tar 打包/解包/压缩/解压缩文件,注意打包和压缩不是一回事,打包相当于捆绑,压缩是在捆绑好后再把里面的空隙挤出以生成更小的文件 $tar [-zjxcvf] filename.tar[.gz... ...

  2. android EditText光标位置(定位到最后)

    方法:edittext.setSelection(int); et.setText(content);//设置EditText控件的内容et.setSelection(content.length() ...

  3. android switch(String)错误:Cannot switch on a value of type String for source level below 1.7

    switch语句的判断条件可以接受int,byte,char,short,不能接受其他类型只有JDK版本1.7以上才可以支持String 设置如下可解决问题:(若没有JDK1.7版,可下载一下安装)菜 ...

  4. Puppet3在CentOS6.5集群下的安装

    环境:3台主机, IP分别为10.211.55.11.12.13 puppet master安装在10.211.55.11 puppet agent安装在10.211.55.11.12.13 1.安装 ...

  5. Ac日记——大整数减法 openjudge 1.6 11

    11:大整数减法 总时间限制:  1000ms 内存限制:  65536kB 描述 求两个大的正整数相减的差. 输入 共2行,第1行是被减数a,第2行是减数b(a > b).每个大整数不超过20 ...

  6. 网络攻防比赛PHP版本WAF

    这次去打HCTF决赛,用了这个自己写的WAF,web基本上没被打,被打的漏洞是文件包含漏洞,这个功能在本人这个waf里确实很是捉急,由于只是简单检测了..和php[35]{0,1},导致比赛由于文件包 ...

  7. poj1273 Drainage Ditches

    Drainage Ditches Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 68414   Accepted: 2648 ...

  8. 代码管理工具之git的学习

    1.代码管理工具git的学习  http://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html 2.github的使用帮助   https:// ...

  9. XML操作类

        using System; using System.Data; using System.IO; using System.Xml; namespace DotNet.Utilities { ...

  10. 树莓派及其他硬件平台国内外Linux镜像站全汇总

    转载至segmentfault. 本文收集整理国内对于Raspberry Pi.CubieBoard.pcDuino等各种Linux开源硬件平台,所使用的Raspbian.Arch Linux ARM ...