AIM Tech Round 5 (rated, Div. 1 + Div. 2)C Rectangles(枚举+前缀和)

解析:我们要找的点肯定在n-1个矩形的公共区域里,所以我们只要找出矩形的公共区域然后取任意一个顶点的值就好了,公共区域通过前缀和可以搞出来

#include<bits/stdc++.h>
using namespace  std;
#define ll long long
#define pb push_back
#define inf 0x3f3f3f3f
#define mod 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
const int N=2e5+10;
int lx1[N],ly1[N],rx1[N],ry1[N],lx2[N],ly2[N],rx2[N],ry2[N];
int px[N],py[N],qx[N],qy[N],n;
int main()
{
    #ifdef local
        freopen("D://r.txt","r",stdin);
    #endif
    ios::sync_with_stdio(false);
    scanf("%d",&n);
    rep(i,1,n+1)
        scanf("%d%d%d%d",px+i,py+i,qx+i,qy+i);
    lx1[0]=-inf;
    rx1[0]=inf;
    ly1[0]=-inf;
    ry1[0]=inf;
    rep(i,1,n+1)
    {
        lx1[i]=max(lx1[i-1],px[i]);
        ly1[i]=max(ly1[i-1],py[i]);
        rx1[i]=min(rx1[i-1],qx[i]);
        ry1[i]=min(ry1[i-1],qy[i]);
    }
    lx2[n+1]=-inf;
    rx2[n+1]=inf;
    ly2[n+1]=-inf;
    ry2[n+1]=inf;
    per(i,1,n+1)
    {
        lx2[i]=max(lx2[i+1],px[i]);
        ly2[i]=max(ly2[i+1],py[i]);
        rx2[i]=min(rx2[i+1],qx[i]);
        ry2[i]=min(ry2[i+1],qy[i]);
    }
    rep(i,1,n+1)
    {
        int lx0=max(lx1[i-1],lx2[i+1]);
        int ly0=max(ly1[i-1],ly2[i+1]);
        int rx0=min(rx1[i-1],rx2[i+1]);
        int ry0=min(ry1[i-1],ry2[i+1]);
        if (lx0<=rx0&&ly0<=ry0)
        {
            printf("%d %d\n",lx0,ly0);
            return 0;
        }
    }
    return 0;
}
posted @ 2018-08-28 17:11  ffgcc  阅读(95)  评论(0编辑  收藏  举报