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
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
using L = long long;
L ansX = 0, ansY = 0;

pair<int, int> pairAdd(pair<int, int> a, pair<int, int> b)
{
    if(a.x == b.x)
        return {a.x, a.y + b.y};
    return max(a, b);
}

struct TR
{
    pair<int, int> maxi;
    int delta;
};

TR tree[1<<21];
int depth = 1;
int n;
int xSize, ySize;

pair<int, int> xPos[500100], yPos[500100];

void addVal(int val, int st, int en, int a = 0, int b = depth - 1, int p = 1)
{
    if(st <= a && b <= en)
    {
        tree[p].delta += val;
        tree[p].maxi.x += val;
        return;
    }
    if(b < st || en < a)
        return;
    addVal(val, st, en, a, (a + b) / 2, p * 2);
    addVal(val, st, en, (a + b) / 2 + 1, b, p * 2 + 1);
    tree[p].maxi = pairAdd(tree[p * 2].maxi, tree[p * 2 + 1].maxi);
    tree[p].maxi.x += tree[p].delta;
}

void initTree()
{
    for(int i = depth - 1; i >= 1; --i)
    {
        tree[i] = {pairAdd(tree[2 * i].maxi, tree[2 * i + 1].maxi), (int)0};
    }
}

int readVal(int p)
{
    int ans = 0;
    while(p)
    {
        ans += tree[p].delta;
        p /= 2;
    }
    return ans;
}

//vector<int> happenings[1000100];

vector<pair<int, int>> scal;
pair<int, int> treePos[1000100];
int calc(pair<int, int> * pos, int dimSize)
{
    pair<int, int> ans = {n, 0};
    scal.clear();
    scal.push_back({0, -999999});
    scal.push_back({dimSize, 999999});
    for(int i = 1; i <= n; ++i)
    {
        if(pos[i].x > pos[i].y)
            swap(pos[i].x, pos[i].y);
        scal.push_back({pos[i].x, -i});
        scal.push_back({pos[i].y, i});
    }
    sort(scal.begin(), scal.end());
    for(int i = 0; i < scal.size(); ++i)
    {
        if(abs(scal[i].y) == 999999)
            continue;
        if(scal[i].y < 0)
            treePos[-scal[i].y].x = i;
        else
            treePos[scal[i].y].y = i;
    }
    for(int i = 0; i < scal.size() - 1; ++i)
    {
        tree[depth + i] = {{0, scal[i + 1].x - scal[i].x}, 0};
    }
    initTree();
    for(int i = 1; i <= n; ++i)
    {
        addVal(1, 0, treePos[i].x - 1);
        addVal(1, treePos[i].y, scal.size() - 1);
    }
    ans = max(ans, tree[1].maxi);
    for(int i = 1; i < scal.size() - 1; ++i)
    {
        /*cout << "=====================\n";
        for(int i = 0; i < depth; ++i)
        {
            cout << readVal(i + depth) << ' ';
        }
        cout << '\n';*/
        if(scal[i].y < 0)
        {
            addVal(-1, 0, scal.size() - 1);
            addVal(2, treePos[-scal[i].y].x, treePos[-scal[i].y].y - 1);
        }
        else
        {
            addVal(1, 0, scal.size() - 1);
            addVal(-2, treePos[scal[i].y].x, treePos[scal[i].y].y - 1);
        }
        ans = max(ans, tree[1].maxi);
        /*cout << tree[1].maxi.x << ' ' << tree[1].maxi.y << ' ' << ans.y << ' ' << scal[i].x << ' ' << scal[i].y << '\n';
        for(int i = 0; i < depth; ++i)
        {
            cout << readVal(i + depth) << ' ';
        }
        cout << '\n';*/
    }
    return ans.y;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> xSize >> ySize;
    while(depth <= n * 2 + 3)
        depth *= 2;
    for(int i = 1; i <= n; ++i)
    {
        int in_x, in_y, in_x2, in_y2;
        cin >> xPos[i].x >> yPos[i].x >> xPos[i].y >> yPos[i].y;
    }
    ansX = calc(xPos, xSize);
    ansY = calc(yPos, ySize);
    cout << ansX * ansY << '\n';
    return 0;
}