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. gitolite 丢失管理密钥/访问权限 解决办法

    登录到服务器. 使用完整路径克隆管理员仓库: git clone $HOME/repositories/gitolite-admin.git temp cd gitolite-admin/conf v ...

  2. Python字符串所有操作函数

    name = "my \tname is {name} and i am {year} old" print(name.capitalize())#首字母大写 print(name ...

  3. POJ 2184 Cow Exhabition

    "Fat and docile, big and dumb, they look so stupid, they aren't much fun..." - Cows with G ...

  4. location 匹配规则 (NGINX)

    转:https://moonbingbing.gitbooks.io/openresty-best-practices/ngx/nginx_local_pcre.html location 匹配规则 ...

  5. "Hello world!"团队第一次会议

    今天是我们"Hello world!"团队第一次召开会议,今天的会议可能没有那么正式,但是我们一起确立了选题——基于WEB的售票系统.博客内容是: 1.会议时间 2.会议成员 3. ...

  6. MFC最基本动作(如创建窗口,点击取消等)函数的执行顺序

    一.MFC应用程序中处理消息的顺序: 1.AfxWndProc()       该函数负责接收消息,找到消息所属的CWnd对象,然后调用AfxCallWndProc2.AfxCallWndProc() ...

  7. 使用cookies模拟登陆

    http://blog.csdn.net/a1099439833/article/details/51918955 使用cookies会话跟踪,保持cookies访问,对于cookies会失效的问题可 ...

  8. python 查看趴下来的数据

    #coding=utf-8 import re from lxml import etree import requests def requests_view(response): import w ...

  9. 【Redis】- 双写一致性

    首先,缓存由于其高并发和高性能的特性,已经在项目中被广泛使用.在读取缓存方面,大家没啥疑问,都是按照下图的流程来进行业务操作. 但是在更新缓存方面,对于更新完数据库,是更新缓存呢,还是删除缓存.又或者 ...

  10. [剑指Offer] 64.滑动窗口的最大值

    题目描述 给定一个数组和滑动窗口的大小,找出所有滑动窗口里数值的最大值.例如,如果输入数组{2,3,4,2,6,2,5,1}及滑动窗口的大小3,那么一共存在6个滑动窗口,他们的最大值分别为{4,4,6 ...