1028C - Rectangles - CodeForces Solution


geometry implementation sortings *1600

Please click on ads to support us..

C++ Code:

#include "bits/stdc++.h"

using namespace std;

#define fi first
#define se second
#define pow2(i) (1ll<<i)
#define bit(mask,i) ((mask>>i)&1)
#define full_bit(i) ((1ll<<i)-1)
#define count_bit(mask) __builtin_popcountll(mask)

const int MAXN = 1e6 + 10;
const int MAXM = 1e6 + 10;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;

const int d4x[] = { 1, -1, 0, 0 };
const int d4y[] = { 0, 0, 1, -1 };

class rect_t {
public:
        int x1, y1, x2, y2;

        rect_t(int _x1 = -1e9, int _y1 = -1e9, int _x2 = 1e9, int _y2 = 1e9): x1(_x1), x2(_x2), y1(_y1), y2(_y2) {}

        rect_t operator & (rect_t a) {
                return rect_t(max(a.x1, x1), max(a.y1, y1), min(a.x2, x2), min(a.y2, y2));
        }
};

void solve() {
        int n;
        cin >> n;

        vector < rect_t > f(n);

        for (auto& [x1, y1, x2, y2] : f) {
                cin >> x1 >> y1 >> x2 >> y2;
        }

        vector < rect_t > l(n + 2);
        vector < rect_t > r(n + 2);

        for (int i = 1; i <= n; i++) {
                l[i] = l[i - 1] & f[i - 1];
        }

        for (int i = n; i >= 1; i--) {
                r[i] = r[i + 1] & f[i - 1];
        }

        for (int i = 1; i <= n; i++) {
                auto [x1, y1, x2, y2] = l[i - 1] & r[i + 1];
                if (x1 <= x2 && y1 <= y2) {
                        cout << x1 << " " << y1;
                        return;
                }
        }
}

signed main() {
        cin.tie(NULL)->sync_with_stdio(false);

        int test = 1;
        // cin >> test;

        while (test--) {
                solve();
        }

        return (0 ^ 0);
}

/* Biết etohari không ? */


Comments

Submit
0 Comments
More Questions

1409A - Yet Another Two Integers Problem
977A - Wrong Subtraction
263A - Beautiful Matrix
180C - Letter
151A - Soft Drinking
1352A - Sum of Round Numbers
281A - Word Capitalization
1646A - Square Counting
266A - Stones on the Table
61A - Ultra-Fast Mathematician
148A - Insomnia cure
1650A - Deletions of Two Adjacent Letters
1512A - Spy Detected
282A - Bit++
69A - Young Physicist
1651A - Playoff
734A - Anton and Danik
1300B - Assigning to Classes
1647A - Madoka and Math Dad
710A - King Moves
1131A - Sea Battle
118A - String Task
236A - Boy or Girl
271A - Beautiful Year
520B - Two Buttons
231A - Team
479C - Exams
1030A - In Search of an Easy Problem
158A - Next Round
71A - Way Too Long Words