hdoj 1823 Luck and Love 【二维线段树】

题目链接:hdoj 1823 Luck and Love

Luck and Love

Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6172 Accepted Submission(s): 1557

Problem Description
世界上上最远的距离不是相隔天涯海角
而是我在你面前
可你却不知道我爱你
―― 张小娴

前段日子,枫冰叶子给Wiskey做了个征婚启事,聘礼达到500万哦,天哪,可是天文数字了啊,不知多少MM蜂拥而至,顿时万人空巷,连扫地的大妈都来凑热闹来了。―_―|||
由于人数太多,Wiskey实在忙不过来,就把统计的事情全交给了枫冰叶子,自己跑回家休息去了。这可够枫冰叶子忙的了,他要处理的有两类事情,一是得接受MM的报名,二是要帮Wiskey查找符合要求的MM中缘分最高值。

Input
本题有多个测试数据,第一个数字M,表示接下来有连续的M个操作,当M=0时处理中止。
接下来是一个操作符C。
当操作符为‘I’时,表示有一个MM报名,后面接着一个整数,H表示身高,两个浮点数,A表示活泼度,L表示缘分值。 (100<=H<=200, 0.0<=A,L<=100.0)
当操作符为‘Q’时,后面接着四个浮点数,H1,H2表示身高区间,A1,A2表示活泼度区间,输出符合身高和活泼度要求的MM中的缘分最高值。 (100<=H1,H2<=200, 0.0<=A1,A2<=100.0)
所有输入的浮点数,均只有一位小数。

Output
对于每一次询问操作,在一行里面输出缘分最高值,保留一位小数。
对查找不到的询问,输出-1。

Sample Input
8
I 160 50.5 60.0
I 165 30.0 80.5
I 166 10.0 50.0
I 170 80.5 77.5
Q 150 166 10.0 60.0
Q 166 177 10.0 50.0
I 166 40.0 99.9
Q 166 177 10.0 50.0
0

Sample Output
80.5
50.0
99.9

二维线段树:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#define PI acos(-1.0)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define fi first
#define se second
#define ll o<<1
#define rr o<<1|1
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 1000 + 10;
const int pN = 1e6;// <= 10^7
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
void add(LL &x, LL y) { x += y; x %= MOD; }
struct Nodey {
    int ly, ry, L;
};
int posx[101], posy[MAXN];
int nx = 101, ny = 1001;
struct Nodex {
    Nodey treey[MAXN<<2];
    int lx, rx;
    void Build_y(int o, int l, int r) {
        treey[o].ly = l; treey[o].ry = r;
        treey[o].L = -1;
        if(l == r) {
            posy[l] = o;
            return ;
        }
        int mid = (l + r) >> 1;
        Build_y(ll, l, mid);
        Build_y(rr, mid+1, r);
    }
    int Query_y(int o, int y1, int y2) {
        if(treey[o].ly == y1 && treey[o].ry == y2) {
            return treey[o].L;
        }
        int mid = (treey[o].ly + treey[o].ry) >> 1;
        if(y2 <= mid) return Query_y(ll, y1, y2);
        else if(y1 > mid) return Query_y(rr, y1, y2);
        else return max(Query_y(ll, y1, mid), Query_y(rr, mid+1, y2));
    }
};
Nodex treex[103<<2];
void Build_x(int o, int l, int r) {
    treex[o].lx = l; treex[o].rx = r;
    treex[o].Build_y(1, 0, ny);
    if(l == r){
        posx[l] = o;
        return ;
    }
    int mid = (l + r) >> 1;
    Build_x(ll, l, mid);
    Build_x(rr, mid+1, r);
}
int Query_x(int o, int x1, int x2, int y1, int y2) {
    if(treex[o].lx == x1 && treex[o].rx == x2) {
        return treex[o].Query_y(1, y1, y2);
    }
    int mid = (treex[o].lx + treex[o].rx) >> 1;
    if(x2 <= mid) return Query_x(ll, x1, x2, y1, y2);
    else if(x1 > mid) return Query_x(rr, x1, x2, y1, y2);
    else return max(Query_x(ll, x1, mid, y1, y2), Query_x(rr, mid+1, x2, y1, y2));
}
void PushUp(int x, int y, int v) {
    treex[x].treey[y].L = max(treex[x].treey[y].L, v);
}
void Update(int x, int y, int v) {
    for(int i = posx[x]; i ; i >>= 1) {
        for(int j = posy[y]; j ; j >>= 1) {
            PushUp(i, j, v);
        }
    }
}
int main()
{
    int n;
    while(scanf("%d", &n), n) {
        Build_x(1, 0, nx);
        while(n--) {
            char op[2];
            int H, h; double A, L;
            scanf("%s", op);
            if(op[0] == 'I') {
                scanf("%d%lf%lf", &H, &A, &L);
                Update(H-100, A*10, L*10);
            }
            else {
                scanf("%d%d%lf%lf", &H, &h, &A, &L);
                if(H > h) swap(H, h); if(A > L) swap(A, L);
                int ans = Query_x(1, H-100, h-100, A*10, L*10);
                if(ans == -1) {
                    printf("-1\n");
                }
                else {
                    printf("%.1lf\n", ans * 1.0 / 10);
                }
            }
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值