Rectangles (prefixes and)

Posted by jack5100nv on Mon, 06 Jan 2020 23:20:16 +0100

meaning of the title

Give $n $rectangles and find a point so that it is at least within $n $matrices

Sol

Ha ha Da, yesterday cf midnight, a whole cut of the topic, I did not do out.. Don't want to find any reason, can't do is can't do..

A very obvious property, if there is a point / rectangle within $n - 1 $rectangle

Their intersection will not be empty.

Then let's enumerate each point, assuming it doesn't intersect $(n - 1) $rectangles, just prefix and suffix and judge

/*

*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long 
#define LL long long 
#define rg register 
#define sc(x) scanf("%d", &x);
#define pt(x) printf("%d ", x);
#define db(x) double x 
#define rep(x) for(int i = 1; i <= x; i++)
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 22)], *p1 = buf, *p2 = buf;
char obuf[1<<24], *O = obuf;
#define OS  *O++ = ' ';
using namespace std;
using namespace __gnu_pbds;
const int MAXN = 1e6 + 10, INF = 1e9 + 10, mod = 1e9 + 7;
const double eps = 1e-9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N;
void print(int x) {
    if(x > 9) print(x / 10);
    *O++ = x % 10 + '0';
}
struct Point {
    int x1, y1, x2, y2;
    Point operator + (const Point &rhs) const {
        return (Point) {max(x1, rhs.x1), max(y1, rhs.y1), min(x2, rhs.x2), min(y2, rhs.y2)};
    }
}P[MAXN], A[MAXN], B[MAXN];
main() {
    N = read(); 
    for(int i = 1; i <= N; i++) {
        P[i].x1 = read(); P[i].y1 = read();
        P[i].x2 = read(); P[i].y2 = read();
    }
    A[1] = P[1]; for(int i = 2; i <= N; i++) A[i] = A[i - 1] + P[i];
    B[N] = P[N]; for(int i = N - 1; i >= 1; i--) B[i] = B[i + 1] + P[i];
    for(int i = 1; i <= N; i++) {
        Point cur;
        if(i == 1) cur = B[2];
        else if(i == N) cur = A[N - 1];
        else cur = A[i - 1] + B[i + 1];
        
        if(cur.x1 <= cur.x2 && cur.y1 <= cur.y2) {
            printf("%d %d", cur.x1, cur.y1); 
            return 0;
        }
    }
    return 0;
}
/*

*/

Topics: C++