题目链接: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. [HOOLOO] zizaco/entrust 5.2.x-dev Class name must be a valid object or a string

    在使用laravel 5.1权限管理,使用  安装 zizaco/entrust 5.2.x-dev的时候执行 php artisan entrust:migration的时候报以下错误: [Symf ...

  2. hdu2222 Keywords Search ac自动机

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=2222 题目: Keywords Search Time Limit: 2000/1000 MS ...

  3. UVALive 5000 Underwater Snipers --二分

    题意:一条河岸线y=k,y>k区域有n个敌人,现在要在y<=k区域布置S个狙击手,狙击手的狙击范围为距离自己半径为D的圆内,问满足能够狙死所有的敌人的情况下,离河岸线最近的那个狙击手的离河 ...

  4. POJ1065Wooden Sticks[DP LIS]

    Wooden Sticks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21902   Accepted: 9353 De ...

  5. 第15章 设备无关位图_15.3 DIB和DDB的结合

    第15章 设备相关位图_15.3 DIB和DDB的结合 15.3.1 从DIB创建DDB (1)hBitmap =CreateDIBitmap(…)——注意这名称会误导,实际上创建的是DDB 参数 说 ...

  6. 这段时间对c#和java的感受

    这段时间对c#和java的感受 虽然很多书上说语法相似,但实际这是一个接近于门外汉的看法 真正的不同是 c#对更贴近系统API,      而java倡导跨平台 因而c#语法关键字更多,更细, 而ja ...

  7. sqlmap小白操作

    转载地儿:http://blog.csdn.net/zgyulongfei/article/details/41017493 对于网络安全人员来说,掌握渗透工具的使用方法是一项必备的技能.然而,一个没 ...

  8. SQL2012连接字符串

    安装了sqlserver2012数据库,测试一包代码,搜索网上的方法,死活连接不上,最后偶然测试通过,居然是连接字符串的问题. “如果开发软件的时候是在局域网或者是在本机,并且数据库不在远程计算机上面 ...

  9. Quartz集群配置

    先看看quartz的持久化基本介绍: 引用 1 大家都清楚quartz最基本的概念就是job,在job内调用具体service完成具体功能,quartz需要把每个job存储起来,方便调度,quartz ...

  10. [No000022]他们说:得诺贝尔奖到底有多难?