You are given n rectangles on a plane with coordinates of their bottom left and upper right points. Some (n−1) of the given n

rectangles have some common point. A point belongs to a rectangle if this point is strictly inside the rectangle or belongs to its boundary.

Find any point with integer coordinates that belongs to at least (n−1)

given rectangles.
Input

The first line contains a single integer n(2≤n≤132674) — the number of given rectangles.

Each the next n lines contains four integers x1, y1, x2 and y2 (−109≤x1<x2≤109, −109≤y1<y2≤109) — the coordinates of

the bottom left and upper right corners of a rectangle.
Output

Print two integers x
and y — the coordinates of any point that belongs to at least (n−1)

given rectangles.
Examples

Input

Copy
3
0 0 1 1
1 1 2 2
3 0 4 1
Output

Copy
1 1
Input

Copy
3
0 0 1 1
0 1 1 2
1 0 2 1
Output

Copy
1 1
Input

Copy
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
Output

Copy
1 1
Input

Copy
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
Output

Copy
3 4
Note

The picture below shows the rectangles in the first and second samples. The possible answers are highlighted.

The picture below shows the rectangles in the third and fourth samples.

暴力枚举+线段树优化
只要满足左下角的坐标的最小值大于等于右上角的坐标的最大值一定有公共区间

#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
int a[][],n;
int tree[][<<];
void build(int l,int r,int root,int dep)
{
tree[dep][root]=dep>?INF:-INF;
if(l==r){
tree[dep][root]=a[l][dep];
return ;
}
int mid=l+r>>;
build(l,mid,root<<,dep);
build(mid+,r,root<<|,dep);
tree[dep][root]=dep>?min(tree[dep][root<<],tree[dep][root<<|]):max(tree[dep][root<<],tree[dep][root<<|]);
}
int query(int l,int r,int root,int L,int R,int dep)
{
if(L>R) return dep>?INF:-INF;
if(L<=l && R>=r){
return tree[dep][root];
}
int ans=dep>?INF:-INF,mid=l+r>>;
if(L<=mid) ans=dep>?min(ans,query(l,mid,root<<,L,R,dep)):max(ans,query(l,mid,root<<,L,R,dep));
if(R>mid) ans=dep>?min(ans,query(mid+,r,root<<|,L,R,dep)):max(ans,query(mid+,r,root<<|,L,R,dep));
return ans;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++){
for(int j=;j<;j++)
scanf("%d",&a[i][j]);
}
for(int i=;i<;i++)
build(,n,,i);
for(int i=;i<=n;i++)
{
int b[];
for(int j=;j<;j++){
if(j>) b[j]=min(query(,n,,,i-,j),query(,n,,i+,n,j));
else b[j]=max(query(,n,,,i-,j),query(,n,,i+,n,j));
}
if(b[]<=b[] && b[]<=b[]) return printf("%d %d\n",b[],b[]),;
}
return ;
}

1028C:Rectangles的更多相关文章

  1. 3.25考试(hnoi难度)----神奇的一日游

    T1怕老婆 有一天hzy9819,来到了一座大城市拥有了属于他自己的一双滑板鞋.但是他还是不满足想要拥有属于自己的一栋楼,他来到了一条宽敞的大道上,一个一个记录着这些楼的层数以方便自己选择. hzy9 ...

  2. 【Ray Tracing The Next Week 超详解】 光线追踪2-6 Cornell box

    Chapter 6:Rectangles and Lights 今天,我们来学习长方形区域光照  先看效果 light 首先我们需要设计一个发光的材质 /// light.hpp // ------- ...

  3. 850. 矩形面积 II

    我们给出了一个(轴对齐的)矩形列表 rectangles . 对于 rectangle[i] = [x1, y1, x2, y2],其中(x1,y1)是矩形 i 左下角的坐标,(x2,y2)是该矩形右 ...

  4. [libgdx游戏开发教程]使用Libgdx进行游戏开发(6)-添加主角和道具

    如前所述,我们的主角是兔子头.接下来我们实现它. 首先对AbstractGameObject添加变量并初始化: public Vector2 velocity; public Vector2 term ...

  5. java web 开发三剑客 -------电子书

    Internet,人们通常称为因特网,是当今世界上覆盖面最大和应用最广泛的网络.根据英语构词法,Internet是Inter + net,Inter-作为前缀在英语中表示“在一起,交互”,由此可知In ...

  6. 所有selenium相关的库

    通过爬虫 获取 官方文档库 如果想获取 相应的库 修改对应配置即可 代码如下 from urllib.parse import urljoin import requests from lxml im ...

  7. Project Euler 85 :Counting rectangles 数长方形

    Counting rectangles By counting carefully it can be seen that a rectangular grid measuring 3 by 2 co ...

  8. Codeforces 372B Counting Rectangles is Fun:dp套dp

    题目链接:http://codeforces.com/problemset/problem/372/B 题意: 给你一个n*m的01矩阵(1 <= n,m <= 40). 然后有t组询问( ...

  9. codeforces 1028C Rectangles【思维】

    题目:戳这里 题意:有n个矩阵,求一个点(保证存在)至少在n-1个点内. 解题思路:因为矩阵与坐标轴平行,所以我们画图可以发现如果存在点满足条件,则这些点中一定有一个是矩阵的顶点.我们可以把所有顶点的 ...

随机推荐

  1. java8 stream 流 例子

    Trader raoul = new Trader("Raoul", "Cambridge"); Trader mario = new Trader(" ...

  2. Five Invaluable Techniques to Improve Regex Performance

    Regular expressions are powerful, but with great power comes great responsibility. Because of the wa ...

  3. SQL学习——基础语句(1)

    简序 1.SQL,指结构化查询语言,全称是 Structured Query Language. 2.SQL 让您可以访问和处理数据库. 3.SQL 是一种 ANSI(American Nationa ...

  4. 列表查询组件代码, 简化拼接条件SQL语句的麻烦

    列表查询组件代码, 简化拼接条件SQL语句的麻烦 多条件查询

  5. POJ 1743 [USACO5.1] Musical Theme (后缀数组+二分)

    洛谷P2743传送门 题目大意:给你一个序列,求其中最长的一对相似等长子串 一对合法的相似子串被定义为: 1.任意一个子串长度都大于等于5 2.不能有重叠部分 3.其中一个子串可以在全部+/-某个值后 ...

  6. Vue官网todoMVC示例

    这个示例是模仿官网示例样式和功能用我自己的方式写的,基本上没有看官网的源码,只参考自定义指令.让我们一步步来探讨一下.官网demo 要实现的功能 单条添加todo 单条删除todo 双击编辑todo ...

  7. s5pv210 fimc 之 fimc-dev.c

    fimc-dev.c 是Samsung FIMC 设备的V4L2 驱动.上层应用直接操作这个设备,进行capture,图片处理,以及overlay输出 http://blog.csdn.net/cxw ...

  8. Git学习总结(8)——Git和SVN之间的基本区别

    GIT不仅仅是个版本控制系统,它也是个内容管理系统(CMS),工作管理系统等.如果你是一个具有使用SVN背景的人,你需要做一定的思想转换,来适应GIT提供的一些概念和特征.所以,这篇文章的主要目的就是 ...

  9. NoReferencedTableError: Foreign key associated with column ** with which to generate a foreign key to target column 'id'

    1.使用 python flask 框架做项目时,在实体类中配置了 映射关系, message: id = db.Column(db.Integer, primary_key=True)message ...

  10. 2015 Multi-University Training Contest 6 hdu 5358 First One

    First One Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...