You are given
n
rectangles on a plane with coordinates of their bottom left and upper right points. Some n-1)of the given nrectangles 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(−109109≤x1<x2≤109≤x1<x2≤109, −109≤y1<y2≤−109≤y1<y2≤109109) — 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
3
0 0 1 1
1 1 2 2
3 0 4 1
output
1 1
input
3
0 0 1 1
0 1 1 2
1 0 2 1
output
1 1
input
4
0 0 5 5
0 0 4 4
1 1 4 4
1 1 4 4
output
1 1
input
5
0 0 10 8
1 2 6 7
2 3 5 6
3 4 4 5
8 1 9 2
output
3 4
因为是n−1n−1个矩形,所以我们可以大力预处理出矩形的前缀交和后缀交,然后暴力枚举另外一个矩形即可
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j;i <= k;++i)
#define repp(i,j,k) for(int i = j;i >= k;--i)
#define rept(i,x) for(int i = linkk[x];i;i = e[i].n)
#define P pair<int,int>
#define Pil pair<int,ll>
#define Pli pair<ll,int>
#define Pll pair<ll,ll>
#define pb push_back
#define pc putchar
#define mp make_pair
#define file(k) memset(k,0,sizeof(k))
#define ll long long
#define ls root * 2
#define rs root * 2 + 1
#define fr first
#define se second
const int INF = 1e9+7;
int n;
P sum[140000] , Sum[140000];
struct data{
int x1,y1,x2,y2;
}a[140000];
P b[140000];
bool ans[140000];
int last[140000];
int read()
{
int sum = 0;char c = getchar();bool flag = true;
while(c < '0' || c > '9') {if(c == '-') flag = false;c = getchar();}
while(c >= '0' && c <= '9') sum = sum * 10 + c - 48,c = getchar();
if(flag) return sum;
else return -sum;
}
P merge(int a,int b,int c,int d)
{
int l = max(a,c);
int r = min(b,d);
if(a == -INF || b == -INF || c == -INF || d == -INF) return mp(-INF,-INF);
else if(a == INF && b == INF) return mp(c,d);
else if(c == INF && d == INF) return mp(a,b);
else if(l > r) return mp(-INF,-INF);
else return mp(l,r);
}
void work(bool flag)
{
rep(i,1,n)
{
sum[i] = merge(sum[i-1].fr,sum[i-1].se,b[i].fr,b[i].se);
Sum[n-i+1] = merge(Sum[n-i+2].fr,Sum[n-i+2].se,b[n-i+1].fr,b[n-i+1].se);
}
rep(i,1,n)
{
P now = merge(sum[i-1].fr,sum[i-1].se,Sum[i+1].fr,Sum[i+1].se);;
if(now.fr == -INF && now.se == -INF) continue;
if(now.fr <= now.se)
{
if(!flag)
{
ans[i] = true;
last[i] = now.fr;
}
else
{
if(ans[i])
{
printf("%d %d\n",last[i],now.fr);
exit(0);
}
}
}
}
}
int main()
{
n = read();
rep(i,1,n) a[i].x1 = read(),a[i].y1 = read(),a[i].x2 = read(),a[i].y2 = read();
b[0].fr = b[0].se = b[n+1].fr = b[n+1].se = INF;
sum[0].fr = sum[0].se = Sum[n+1].fr = Sum[n+1].se = INF;
rep(i,1,n) b[i].fr = a[i].x1,b[i].se = a[i].x2;
work(0);
rep(i,1,n) b[i].fr = a[i].y1,b[i].se = a[i].y2;
work(1);
return 0;
}