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. TensorFlow入门之MNIST最佳实践-深度学习

    在上一篇<TensorFlow入门之MNIST样例代码分析>中,我们讲解了如果来用一个三层全连接网络实现手写数字识别.但是在实际运用中我们需要更有效率,更加灵活的代码.在TensorFlo ...

  2. 预分配内存fifo实现可变长度字节序列存储

    预分配内存fifo实现可变长度字节序列存储 github链接https://github.com/gexin1023/utils/tree/master/fifo fifo即先进先出队列,可以用链表来 ...

  3. 十:HDFS Short-Circuit Local Reads 短路本地读取

    当client请求数据时,datanode会读取数据然后通过TCP协议发送给client.short-circuit绕过了datanode直接读取数据.short-circuit的前提是client和 ...

  4. ZOJ 2532 Internship(最大流找关键割边)

    Description CIA headquarter collects data from across the country through its classified network. Th ...

  5. v-if或者v-repeat等不起作用

    v-if或者v-for等不起作用 在项目中,有时遇到了v-if或v-for等形式时,页面没起作用.以下可能是出现这些问题的原因: 1.绑定值是接口返回的某个属性值,而这个属性值不存在data()中,这 ...

  6. windows编程了解

    文章:浅谈Windows API编程 (这个经典)

  7. VS2013 “未找到与约束 ContractName Microsoft.Internal.VisualStudio.PlatformUI.ISolutionAttachedCollectionService RequiredTypeIdentity Microsoft.Internal.VisualStudio.PlatformUI.ISolutionAttachedCollectionService 匹配的导出”

    下面是我出错误的附加图片 这个错误导致无法打开项目. 解决方法: 解: C:\Users\Administrator\AppData\Local\Microsoft\VisualStudio\12.0 ...

  8. 【Docker 命令】- attach命令

    docker attach :连接到正在运行中的容器. 语法 docker attach [OPTIONS] CONTAINER 要attach上去的容器必须正在运行,可以同时连接上同一个contai ...

  9. monaco editor 实现自定义提示(sql为例)

    monaco editor :https://www.cnblogs.com/XHappyness/p/9414177.html 这里实现自己定义的提示: .vue <template> ...

  10. c#控件的name和text属性有什么不同?

    text 是显示出来,供用户和自己编辑方便使用的,name 属性是编辑代码用的. 比如要读取一个text栏的内容 取name='txtName' text='姓名'代码段需要写的是, txtName. ...