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
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <algorithm>
#include <vector>

typedef long long int ll;
typedef std::pair<ll, ll> pll;

ll N, X, Y;

ll T_ADD[1048 * 2048], T_MAX[1048 * 2048], T_SUM[1048 * 2048]; // span tree with (add, max, sum)
ll BASE;

pll X_PAIRS[1024 * 512], Y_PAIRS[1024 * 512]; // set of X & Y pairs

std::set<ll> X_PTS, Y_PTS; // set of point, for later use
std::vector<ll> PTS;
std::map<ll, ll> PTS_MAP;


void input() {
    std::cin >> N >> X >> Y;

    X_PTS.insert(0);
    X_PTS.insert(X);

    Y_PTS.insert(0);
    Y_PTS.insert(Y);

    for (int i = 0; i < N; i++) {
        ll a, b, c, d;
        std::cin >> a >> b >> c >> d;
        X_PAIRS[i] = std::make_pair(std::max(a, c), std::min(a, c));
        Y_PAIRS[i] = std::make_pair(std::max(b, d), std::min(b, d));

        X_PTS.insert(a);
        X_PTS.insert(c);

        Y_PTS.insert(b);
        Y_PTS.insert(d);
    }

    std::sort(X_PAIRS, X_PAIRS + N);
    std::sort(Y_PAIRS, Y_PAIRS + N);
}

void clean_pts_map() {
    PTS_MAP = std::map<ll, ll>();
    for (int i = 0; i < PTS.size(); i++)
        PTS_MAP.insert(std::make_pair(PTS[i], i));
}

void clean_tree() {
    BASE = 1;
    while (BASE < PTS.size())
        BASE *= 2;

    for (ll i = 1; i < BASE * 2; i++)
        T_ADD[i] = T_MAX[i] = T_SUM[i] = 0;

    for (ll i = 0; i < PTS.size() - 1; i++)
        T_SUM[i + BASE] = PTS[i + 1] - PTS[i];
    for (ll i = BASE - 1; i >= 1; i--)
        T_SUM[i] = T_SUM[2 * i] + T_SUM[2 * i + 1];
}

void bump_leaf(ll leaf, ll d) {
    T_ADD[leaf] += d;
    T_MAX[leaf] += d;
}

void balance_node(ll node) {
    T_MAX[node] = std::max(T_MAX[node * 2], T_MAX[node * 2 + 1]);

    T_SUM[node] = 0;
    if (T_MAX[node] == T_MAX[node * 2])
        T_SUM[node] += T_SUM[node * 2];
    if (T_MAX[node] == T_MAX[node * 2 + 1])
        T_SUM[node] += T_SUM[node * 2 + 1];

    T_MAX[node] += T_ADD[node];
}

//void show() {
//    int POW = 2;
//    for (int i = 1; i < BASE * 2; i++) {
//        if (i == POW) {
//            std::cout << std::endl;
//            POW *= 2;
//        }
//        std::cout << "[" << T_MAX[i] << ", " << T_ADD[i] << ", " << T_SUM[i] << "] ";
//    }
//    std::cout << std::endl;
//}

void add_d(ll left_pt, ll right_pt, ll d) {
    if (left_pt >= right_pt) return;

    ll left = BASE + PTS_MAP.find(left_pt) -> second;
    ll right = BASE + PTS_MAP.find(right_pt) -> second - 1;

    bump_leaf(left, d);
    if (left != right)
        bump_leaf(right, d);

    while (left / 2 != right / 2) { // dopóki nie są rodzenstwem
        if (left % 2 == 0)
            bump_leaf(left + 1, d);
        if (right % 2 == 1)
            bump_leaf(right - 1, d);

        left /= 2;
        right /= 2;

        balance_node(left);
        balance_node(right);
    }

    while(left != 1) {
        left /= 2;
        balance_node(left);
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    input();

    // first, X axis
    PTS = std::vector<ll>(X_PTS.begin(), X_PTS.end());
    clean_pts_map();
    clean_tree();

    for (int i = 0; i < N; i ++) { // initialize
        pll pair = X_PAIRS[i];
        add_d(pair.second, pair.first, 1);
    }

    ll BEST_X_SCORE = T_MAX[1] == N ? T_SUM[1] : 0;

    for (int i = 0; i < N; i ++) { // reversal
        pll pair = X_PAIRS[i];
        add_d(pair.second, pair.first, -1);
        add_d(0, pair.second, 1);
        add_d(pair.first, X, 1);

        BEST_X_SCORE = std::max(BEST_X_SCORE, T_MAX[1] == N ? T_SUM[1] : 0);
    }

    for (int i = 0; i < N; i ++) { // normalize
        pll pair = X_PAIRS[i];
        add_d(0, pair.second, -1);
        add_d(pair.first, X, -1);
        add_d(pair.second, pair.first, 1);

        BEST_X_SCORE = std::max(BEST_X_SCORE, T_MAX[1] == N ? T_SUM[1] : 0);
    }

    // next, Y_axis
    PTS = std::vector<ll>(Y_PTS.begin(), Y_PTS.end());
    clean_pts_map();
    clean_tree();

    for (int i = 0; i < N; i ++) { // initialize
        pll pair = Y_PAIRS[i];
        add_d(pair.second, pair.first, 1);
    }

    ll BEST_Y_SCORE = T_MAX[1] == N ? T_SUM[1] : 0;

    for (int i = 0; i < N; i ++) { // reversal
        pll pair = Y_PAIRS[i];
        add_d(pair.second, pair.first, -1);
        add_d(0, pair.second, 1);
        add_d(pair.first, Y, 1);

        BEST_Y_SCORE = std::max(BEST_Y_SCORE, T_MAX[1] == N ? T_SUM[1] : 0);
    }

    for (int i = 0; i < N; i ++) { // normalize
        pll pair = Y_PAIRS[i];
        add_d(0, pair.second, -1);
        add_d(pair.first, Y, -1);
        add_d(pair.second, pair.first, 1);

        BEST_Y_SCORE = std::max(BEST_Y_SCORE, T_MAX[1] == N ? T_SUM[1] : 0);
    }

    std::cout << BEST_X_SCORE * BEST_Y_SCORE << std::endl;
}