1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <cstdio>
#include <utility>
#include <set>
#include <vector>
#include <algorithm>

#define REP(a, n) for (int a = 0; a < (n); ++a)
#define FOR(a, b, c) for (int a = (b); a <= (c); ++a)

#define INF 1000000000

typedef long long LL;

using namespace std;

//////////////////////

int N;

int best;
set<int> granice;
vector<pair<int, int>> otwarte;

void czysc_do(int x1) {
    while (*next(granice.begin()) <= x1) {
        int xa = *granice.begin();
        int xb = *next(granice.begin());
        int len = xb - xa;
        if (otwarte.back().first == xb) {
            len += otwarte.back().second;
            otwarte.pop_back();
        }
        best = max(best, len);
        granice.erase(xa);
    }
    int xa = *granice.begin();
    int xb = *next(granice.begin());
    int add = x1 - xa;
    if (otwarte.back().first == xb)
        otwarte.back().second += add;
    else
        otwarte.emplace_back(xb, add);
    granice.erase(xa);
}

int solve(pair<int, int> *tab, int XS) {
    REP(a, N)
        if (tab[a].first > tab[a].second)
            swap(tab[a].first, tab[a].second);
    tab[N++] = make_pair(XS - 1, XS - 1);
    sort(tab, tab + N);
    granice.clear();
    granice.insert(0);
    granice.insert(XS);
    otwarte.clear();
    otwarte.emplace_back(XS, 0);
    best = 0;
    REP(a, N) {
        int x1 = tab[a].first;
        int x2 = tab[a].second;
        czysc_do(x1);
        granice.insert(x1);
        while (otwarte.back().first <= x2) {
            best = max(best, otwarte.back().second);
            otwarte.pop_back();
        }
        granice.insert(x2);
    }
    best = max(best, otwarte.back().second + 1); // zewnętrzny
    return best;
}

pair<int, int> tabx[500001], taby[500001];

int main() {
    int XS, YS;
    scanf("%d%d%d", &N, &XS, &YS);
    REP(a, N)
        scanf("%d%d%d%d", &tabx[a].first, &taby[a].first, &tabx[a].second, &taby[a].second);
    LL res = solve(tabx, XS);
    res *= solve(taby, YS);
    printf("%lld\n", res);
}