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. javascript动画函数封装

    function animate(obj, target) { clearInterval(obj.timer); obj.timer = setInterval(function () { var ...

  2. UDP协议总结

    我们已经讲解了物理层.连接层和网络层.最开始的连接层协议种类繁多(Ethernet.Wifi.ARP等等).到了网络层,我们只剩下一个IP协议(IPv4和IPv6是替代关系).进入到传输层(trans ...

  3. POJ.grids.2980

    题目链接:http://bailian.openjudge.cn/practice/2980 解题思路:先将对应位相乘的积累加,最后再来处理进位问题:如 835*49: 先做 835*9: 得到 i  ...

  4. Unity坐标系 左手坐标系 图

    x轴:从左指向右 y轴:从下指向上 z轴:指向屏幕里的是左手坐标系,指向屏幕外的是右手坐标系 记忆小技巧:都是X轴朝右,Y轴向上,跟平时画坐标一模一样,区别只是Z的朝向.你用手试一下就知道了,当大拇指 ...

  5. day02 操作系统与编程语言

    目录 操作系统 操作系统是什么 操作系统做了什么 文件是什么? 为什么要有操作系统 操作系统有什么用 应用程序的启动和操作系统的启动 复盘QQ的启动 操作系统启动的流程 编程语言分类 机器语言 汇编语 ...

  6. ThoughtWorks 技术雷达(2013年5月)

    ThoughtWorks技术雷达(2013年5月) 作者ThoughtWorks技术战略委员会 发布于 六月 25, 2013| 讨论 新浪微博腾讯微博 豆瓣网 Twitter Facebook li ...

  7. NotFoundHttpException

    报错:NotFoundHttpException 这种一般都是路由配置错误

  8. 三、frpc 完整配置文件

    # [common] is integral section [common] # A literal address or host name for IPv6 must be enclosed # ...

  9. keepalived 和 heartbeat对比

    Keepalived使用的vrrp协议方式,虚拟路由冗余协议 (Virtual Router Redundancy Protocol,简称VRRP): Heartbeat是基于主机或网络的服务的高可用 ...

  10. MySQL创建表时加入的约束以及外键约束的的意义

    1,创建表时加入的约束 a) 非空约束,not null b) 唯一约束,unique c) 主键约束,primary key d) 外键约束,foreign key 1,非空约束,针对某个字段设置其 ...