xiaoz 征婚,首先输入M,表示有M个操作。

借下来M行,对每一行   Ih a l     I 表示有一个MM报名,H是高度, a是活泼度,L是缘分。

或   Q h1 h2 a1 a2    求出身高在h1  h2  活泼度在a1  a2之间的最大缘分值。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <iomanip>
#include <cstdlib>
#include <sstream>
using namespace std;
typedef long long LL;
const int INF=0x5fffffff;
const double EXP=1e-;
const int MS=; struct active
{
int l,r;
double maxv;
int mid()
{
return (l+r)>>;
}
}; struct node
{
int l,r;
active actives[*MS];
int mid()
{
return (l+r)>>;
}
}nodes[]; void init()
{
for(int i=;i<;i++)
for(int j=;j<*MS;j++)
nodes[i].actives[j].maxv=-;
} void creat_a(int p,int root,int l,int r)
{
nodes[p].actives[root].l=l;
nodes[p].actives[root].r=r;
if(nodes[p].actives[root].l==nodes[p].actives[root].r)
return ;
int mid=(l+r)/;
creat_a(p,root<<,l,mid);
creat_a(p,root<<|,mid+,r);
} void creat(int root,int l,int r)
{
nodes[root].l=l;
nodes[root].r=r;
creat_a(root,,,MS);
if(nodes[root].l==nodes[root].r)
return ;
int mid=(l+r)/;
creat(root<<,l,mid);
creat(root<<|,mid+,r);
} void insert_a(int p,int root,int pos,double value)
{
if(nodes[p].actives[root].maxv<value)
nodes[p].actives[root].maxv=value;
if(nodes[p].actives[root].l==nodes[p].actives[root].r)
return ;
if(pos<=nodes[p].actives[root].mid())
insert_a(p,root<<,pos,value);
else
insert_a(p,root<<|,pos,value);
} void insert(int root,int pos,int value,double s)
{
insert_a(root,,value,s);
if(nodes[root].l==nodes[root].r)
return ;
if(pos<=nodes[root].mid())
insert(root<<,pos,value,s);
else
insert(root<<|,pos,value,s);
} double query_a(int p,int root,int l,int r)
{
double ans=-;
if(nodes[p].actives[root].l>=l&&nodes[p].actives[root].r<=r)
return nodes[p].actives[root].maxv;
if(l<=nodes[p].actives[root].mid())
ans= max(ans,query_a(p,root<<,l,r));
if(r>nodes[p].actives[root].mid())
ans=max(ans,query_a(p,root<<|,l,r));
return ans;
} double query(int root,int l1,int r1,int l2,int r2)
{
double ans=-;
if(nodes[root].l>=l1&&nodes[root].r<=r1)
return query_a(root,,l2,r2);
// 如果是叶子节点会在上一条语句中返回。
if(l1<=nodes[root].mid())
ans=max(ans,query(root<<,l1,r1,l2,r2));
if(r1>nodes[root].mid())
ans=max(ans,query(root<<|,l1,r1,l2,r2));
return ans;
} int main()
{
int n,h1,h2;
double a1,a2,fate;
creat(,,);
while(scanf("%d",&n)==&&n)
{
init();
char cmd[MS];
while(n--)
{
scanf("%s",cmd);
if(cmd[]=='I')
{
scanf("%d %lf %lf",&h1,&a1,&fate); insert(,h1,(int)(a1*+EXP),fate);
}
else
{
scanf("%d %d %lf %lf",&h1,&h2,&a1,&a2);
if(h1>h2)
swap(h1,h2);
if(a1>a2)
swap(a1,a2);
double ans=query(,h1,h2,(int)(a1*+EXP),(int)(a2*+EXP));
if(ans>=)
printf("%.1lf\n",ans);
else
printf("-1\n");
}
}
}
return ;
}

二维线段树 HDU 1823最简单的入门题的更多相关文章

  1. poj 2155:Matrix(二维线段树,矩阵取反,好题)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17880   Accepted: 6709 Descripti ...

  2. HDU 1823 Luck and Love(二维线段树)

    之前只知道这个东西的大概概念,没具体去写,最近呵呵,今补上. 二维线段树 -- 点更段查 #include <cstdio> #include <cstring> #inclu ...

  3. HDU 1823 Luck and Love 二维线段树(树套树)

    点击打开链接 Luck and Love Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

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

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

  5. hdu 4819 二维线段树模板

    /* HDU 4819 Mosaic 题意:查询某个矩形内的最大最小值, 修改矩形内某点的值为该矩形(Mi+MA)/2; 二维线段树模板: 区间最值,单点更新. */ #include<bits ...

  6. HDU 4819 Mosaic (二维线段树)

    Mosaic Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others)Total S ...

  7. HDU 4819 Mosaic --二维线段树(树套树)

    题意: 给一个矩阵,每次查询一个子矩阵内的最大最小值,然后更新子矩阵中心点为(Max+Min)/2. 解法: 由于是矩阵,且要求区间最大最小和更新单点,很容易想到二维的线段树,可是因为之前没写过二维的 ...

  8. HDU 4819 Mosaic 二维线段树

    Mosaic Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action ...

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

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

随机推荐

  1. 一些不错的英文歌曲MV,留个存档!

    Lambada [[http://www.yinyuetai.com/video/265213]]Trouble Is A Friend [[http://www.yinyuetai.com/vide ...

  2. leetcode@ [355] Design Twitter (Object Oriented Programming)

    https://leetcode.com/problems/design-twitter/ Design a simplified version of Twitter where users can ...

  3. homework-01 "最大子数组之和"的问题求解过程

    写在前面:我的算法能力很弱,并且也是第一次写博文,总之希望自己能在这次的课程中学到很多贴近实践的东西吧. 1.这次的程序是python写的,这也算是我第一次正正经经地拿python来写东西,结果上来说 ...

  4. Spring入门(8)-基于Java配置而不是XML

    Spring入门(8)-基于Java配置而不是XML 本文介绍如何应用Java配置而不是通过XML配置Spring. 0. 目录 声明一个简单Bean 声明一个复杂Bean 1. 声明一个简单Bean ...

  5. thymeleaf中的条件判断用法

    一.简单的条件:“if”和“unless” th:if用法实例: <table> <tr> <th>NAME</th> <th>PRICE& ...

  6. ios游戏开发 Sprite Kit教程:初学者 1

    注:本文译自Sprite Kit Tutorial for Beginners 目录 Sprite Kit的优点和缺点 Sprite Kit vs Cocos2D-iPhone vs Cocos2D- ...

  7. HTML5学习笔记(一):HTML简介

    Web前端涵盖的内容较多且杂,主要由3个部分组成:HTML标记语言.CSS样式语言和JavaScript脚本语言组成,而下面我们将先学习最新的标记语言HTML5. <!DOCTYPE>标记 ...

  8. 让EditText不能自动获取焦点

    在activity中放置了1个或1个以上的EditText,进入该activity的时候第一个EditText会接收焦点,我希望里面所有的EditText默认是不接收焦点的,该怎么做呢? 方法: 在第 ...

  9. TChromeTabs 优化改进

    已知未解决问题 全屏时当窗体失去焦点,则会显示出未绘制完成的原标题栏(Fixed): 处于非 Areo 效果下时,窗体标题栏需要定制. 新增按钮上的 Hint 提示后再移至其它标签,将无法重新提示. ...

  10. 中国软件开发project师之痛

    在最近的一次会议上,有高层谈到之前在中国觉得自己做得非常牛,但与美国同行接触后却发现与人家存在非常大的差距,这一点我在外企工作时也有过相同的体会.真正与外国同行接触后才会知道什么是差距,在这篇文章中我 ...