AIM Tech Round 5 (rated, Div. 1 + Div. 2) C

博客围绕平面上n个矩形展开,已知其中(n - 1)个矩形有公共点,要求找出一个整数坐标点,使其至少属于(n - 1)个给定矩形。给出了输入输出格式及示例,还提到可通过预处理矩形的前缀交和后缀交,暴力枚举另外一个矩形来解决问题。

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(−109109x1<x2109≤x1<x2≤109, 109y1<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


因为是n1n−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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值