Luck and Love

Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 50 Accepted Submission(s): 20
 
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
 
Author
威士忌
 
Source
HDOJ 2007 Summer Exercise(3)- Hold by Wiskey
 

代码:

//二维线段树模板,身高一维,欢乐度二维。
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const int maxn=;
struct sub_tree{
int l,r,ans;
int mid(){return (l+r)>>;}
};
struct tree{
int l,r;
int mid(){return (l+r)>>;}
sub_tree st[*maxn];
}tr[*maxn];
void build_subtree(int l,int r,int i,int fa){
tr[fa].st[i].l=l;
tr[fa].st[i].r=r;
tr[fa].st[i].ans=-;
if(l==r) return;
int m=(l+r)>>;
build_subtree(l,m,i<<,fa);
build_subtree(m+,r,i<<|,fa);
}
void build(int l,int r,int i){
tr[i].l=l;tr[i].r=r;
build_subtree(,,,i);
if(l==r) return;
int m=(l+r)>>;
build(l,m,i<<);
build(m+,r,i<<|);
}
void up(int i,int fa){
tr[fa].st[i].ans=max(tr[fa].st[i<<].ans,tr[fa].st[i<<|].ans);
}
void update_subtree(int a,int l,int i,int fa){
if(tr[fa].st[i].l==tr[fa].st[i].r){
tr[fa].st[i].ans=max(tr[fa].st[i].ans,l);
return;
}
int m=tr[fa].st[i].mid();
if(a<=m) update_subtree(a,l,i<<,fa);
else update_subtree(a,l,i<<|,fa);
up(i,fa);
}
void update(int h,int a,int l,int i){
update_subtree(a,l,,i);
if(tr[i].l==tr[i].r) return;
int m=tr[i].mid();
if(h<=m) update(h,a,l,i<<);
else update(h,a,l,i<<|);
}
int query_subtree(int a1,int a2,int i,int fa){
if(tr[fa].st[i].l>=a1&&tr[fa].st[i].r<=a2) return tr[fa].st[i].ans;
int m=tr[fa].st[i].mid();
int Max=-;
if(a1<=m) Max=max(Max,query_subtree(a1,a2,i<<,fa));
if(a2>m) Max=max(Max,query_subtree(a1,a2,i<<|,fa));
return Max;
}
int query(int h1,int h2,int a1,int a2,int i){
if(tr[i].l>=h1&&tr[i].r<=h2) return query_subtree(a1,a2,,i);
int m=tr[i].mid();
int Max=-;
if(h1<=m) Max=max(Max,query(h1,h2,a1,a2,i<<));
if(h2>m) Max=max(Max,query(h1,h2,a1,a2,i<<|));
return Max;
}
int main()
{
int t,h1,h2;
double a1,a2,c;
char ch[];
while(scanf("%d",&t)&&t){
build(,,);
while(t--){
scanf("%s",ch);
if(ch[]=='I'){
scanf("%d%lf%lf",&h1,&a1,&c);
update(h1,a1*,c*,);
}
else{
scanf("%d%d%lf%lf",&h1,&h2,&a1,&a2);
if(h1>h2) swap(h1,h2);
if(a1>a2) swap(a1,a2);
int ans=query(h1,h2,a1*,a2*,);
if(ans<) printf("-1\n");
else printf("%.1lf\n",(double)ans/10.0);
}
}
}
return ;
}

HDU1832 二维线段树求最值(模板)的更多相关文章

  1. HDU 4819 Mosaic (二维线段树&区间最值)题解

    思路: 二维线段树模板题,马克一下,以后当模板用 代码: #include<cstdio> #include<cmath> #include<cstring> #i ...

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

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

  3. poj 1195:Mobile phones(二维线段树,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14391   Accepted: 6685 De ...

  4. HDU 4819 Mosaic(13年长春现场 二维线段树)

    HDU 4819 Mosaic 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4819 题意:给定一个n*n的矩阵,每次给定一个子矩阵区域(x,y,l) ...

  5. tyvj P1716 - 上帝造题的七分钟 二维树状数组区间查询及修改 二维线段树

    P1716 - 上帝造题的七分钟 From Riatre    Normal (OI)总时限:50s    内存限制:128MB    代码长度限制:64KB 背景 Background 裸体就意味着 ...

  6. UVALive 6709 - Mosaic 二维线段树

    题目链接 给一个n*n的方格, 每个方格有值. 每次询问, 给出三个数x, y, l, 求出以x, y为中心的边长为l的正方形内的最大值与最小值, 输出(maxx+minn)/2, 并将x, y这个格 ...

  7. bzoj4785:[ZJOI2017]树状数组:二维线段树

    分析: "如果你对树状数组比较熟悉,不难发现可怜求的是后缀和" 设数列为\(A\),那么可怜求的就是\(A_{l-1}\)到\(A_{r-1}\)的和(即\(l-1\)的后缀减\( ...

  8. [JZOJ3615]【NOI2014模拟】数列(平面几何+二维线段树)

    Description 给定一个长度为n的正整数数列a[i]. 定义2个位置的f值为两者位置差与数值差的和,即f(x,y)=|x-y|+|a[x]-a[y]|. 你需要写一个程序支持2种操作(k都是正 ...

  9. BZOJ 4785 [Zjoi2017]树状数组 | 二维线段树

    题目链接 BZOJ 4785 题解 这道题真是令人头秃 = = 可以看出题面中的九条可怜把求前缀和写成了求后缀和,然后他求的区间和却仍然是sum[r] ^ sum[l - 1],实际上求的是闭区间[l ...

随机推荐

  1. CSP201609-1:最大波动

    引言:CSP(http://www.cspro.org/lead/application/ccf/login.jsp)是由中国计算机学会(CCF)发起的"计算机职业资格认证"考试, ...

  2. 剑指offer-包含min函数的栈20

    题目描述 定义栈的数据结构,请在该类型中实现一个能够得到栈中所含最小元素的min函数(时间复杂度应为O(1)). class Solution: def __init__(self): self.st ...

  3. 你真的了解JAVA里的String么

    Java中String类细节问题 (考察点Java内存分配问题) 1. String str1 = "abc";   System.out.println(str1 == &quo ...

  4. HADOOP docker(八):hadoop本地库

    前言2. Native Hadoop Library3. 使用本地库4. 本地库组件5. 支持的平台6. 下载7. 编译8. 运行时观察9. 检查本地库10. 如果共享本地库 小伙伴还记得每次启动hd ...

  5. Codeforces 96D Volleyball(最短路径)

    Petya loves volleyball very much. One day he was running late for a volleyball match. Petya hasn't b ...

  6. Python 零碎信息-基础 01

    1. """ 可以插入多行文字. print """ abC 123' 456''" #单引号, 双引号, 也没有关系 " ...

  7. node必学的Hello World实现--服务器实现

    node是JavaScript运行在后端的一种实现.而后端语言,不管是php,java都需要一个服务器才能跑起来,node如是. node的服务器较php而言,少了单独安装服务器的步骤,node的服务 ...

  8. 【Docker 命令】- exec命令

    docker exec :在运行的容器中执行命令 语法 docker exec [OPTIONS] CONTAINER COMMAND [ARG...] OPTIONS说明: -d:分离模式: 在后台 ...

  9. div、span绑定内容改变事件

    内容改变事件onchange只适用于form表单标签(input.select.textarea) 当需要对div.span标签进行内容改变监听则无法适用,查阅了一些资料发现jquery有针对的方法, ...

  10. Java判断数据库表是否存在的方法

    一.需求 最近在写一个程序,需要取数据库表的数据之前,需要先查看数据库是否存在该表否则就跳过该表. 二.解决方案(目前想到两种,以后遇到还会继续添加): .建立JDBC数据源,通过Java.sql.D ...