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
#include <bits/stdc++.h>

using namespace std;

//#define int long long

const bool debug = false;

#define cerr if (!debug) {} else cout 
#define pisz(x) cerr << #x << ": " << x << endl;

const int INF = numeric_limits<int>::max() / 4 - 10;

struct Moj {
    int gdzie;
    int a, b;
    
    bool operator<(const Moj &other) const {
        return gdzie < other.gdzie;
    }
};

const int baza = 1 << 20;
int mi[2 * baza], to_push[2 * baza], ile[2 * baza];

int co, pyt_pocz, pyt_kon;

void dodaj22(int pocz = 0, int kon = baza, int gdzie = 1) {
    if (pyt_pocz <= pocz && kon <= pyt_kon) {
        mi[gdzie] += co;
        to_push[gdzie] += co;
        return;
    }
    
    if (kon <= pyt_pocz || pyt_kon <= pocz) {
        return;
    }
    
    int sr = (pocz + kon) >> 1;
    dodaj22(pocz, sr, gdzie << 1);
    dodaj22(sr, kon, (gdzie << 1) + 1);
    mi[gdzie] = min(mi[(gdzie << 1)], mi[(gdzie << 1) + 1]);
    ile[gdzie] = 0;
    if (mi[(gdzie << 1)] == mi[gdzie]) ile[gdzie] += ile[(gdzie << 1)];
    if (mi[(gdzie << 1) + 1] == mi[gdzie]) ile[gdzie] += ile[(gdzie << 1) + 1];
    mi[gdzie] += to_push[gdzie];
}

inline void dodaj(int c, int pp, int pk) {
    co = c;
    pyt_pocz = pp;
    pyt_kon = pk;
    dodaj22();
}

void czysc() {
    for (int i = 0; i < 2 * baza; i++) {
        mi[i] = ile[i] = to_push[i] = 0;
    }
}

void init(int gdzie, int c) {
    gdzie += baza;
    while (gdzie) {
        ile[gdzie] += c;
        gdzie >>= 1;
    }
}

long long algo(vector<pair<int, int> > &tab, int maks) {
    czysc();
    vector<Moj> v;
    
    map<int, int> mapa;
    set<int> s {0, maks};
    
    for (auto &i : tab) {
        if (i.first > i.second) {
            swap(i.first, i.second);
        }
        s.insert(i.first);
        s.insert(i.second);
    }

    int pop = 0;
    int li = 0;
    for (int i : s) {
        mapa[i] = li;
        if (li)
            init(li - 1, i - pop);
        //cout << i << " " << li << " " << i - pop << endl;
        pop = i;
        ++li;
    }
    //init(li - 1, -1);
    //cout << " " << ile[1] << endl;
    
    for (auto &i : tab) {
        i.first = mapa[i.first];
        i.second = mapa[i.second];
        dodaj(1, i.first, i.second);
        v.push_back({i.first, i.first, i.second});
        v.push_back({i.second, i.first, i.second});
    }
    
    int res = 0;
    if (mi[1] == 0) res = ile[1];
    
    //cout << "start" << endl;
    
    sort(v.begin(), v.end());
    for (Moj &i : v) {
        //cout << i.gdzie << endl;
        if (i.gdzie == i.a) {
            dodaj(-2, i.a, i.b);
            dodaj(1, 0, baza);
        } else {
            dodaj(2, i.a, i.b);
            dodaj(-1, 0, baza);
        }
        
        if (mi[1] == 0) res = max(res, ile[1]);
    }
    
    //cout << res << endl;
    
    return res;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    //cout << sizeof(__pom); return 0;
    
    int n = 500000, X = 1000000000, Y = 1000000000;
    cin >> n >> X >> Y;
    vector<pair<int, int> > v[2];
    int a = 0;
    for (int x1, x2, y1, y2, i = 0; i < n; i++) {
        /*x1 = rand() % X;
        x2 =  rand() % X;
        y1 = rand() % Y;
        y2 =  rand() % Y;*/
        cin >> x1 >> y1 >> x2 >> y2;
        v[0].push_back({x1, x2});
        v[1].push_back({y1, y2});
    }
    
    //cout << algo(v[0], X) << endl; cout << algo(v[1], Y) << endl;
    cout << algo(v[0], X) * algo(v[1], Y); 

    return 0;
}
/*

 */