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
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cassert>
#include <map>

#define REP(x, n) for(int x = 0; x<(n); ++x)

struct CoverTree {
#define NRD (wp + wk + 1)>>1
    int *el,*ma,s,p,k,il;

    CoverTree(int size) {
        el = new int[s=1<<(size+1)];
        ma = new int[s];
        REP(x,s)el[x] =ma[x] =0;
    }

    ~CoverTree(){
        delete[] el;
        delete[] ma;
    }

    void Mark(int wp,int wk,int g) {
        if(k<=wp || p>=wk) return;
        if (p<=wp && k>=wk) el[g] +=il;
        else{
            Mark(wp,NRD,2*g);
            Mark(NRD,wk,2*g+1);
        }
        ma[g] = el[g]>0?wk-wp:(wk-1==wp?0:ma[2*g]+ma[2*g+1]);
    }

    void Add(int p1,int k1,int i1){
        p=p1;
        k=k1;
        il=i1;
        Mark(0,s/2,1);
    }

    int F(int wp,int wk,int g){
        if(wp>=k || wk<=p) return 0;
        if(el[g]>0) return std::min(k,wk) - std::max(p,wp);
        if (p<=wp && wk<=k) return ma[g];
        return wp==wk-1?0:F(wp,NRD,2*g)+F(NRD,wk,2*g+1);
    }

    int Find(int p1,int k1){
        p=p1;
        k=k1;
        return F(0,s/2,1);
    }
};

struct Record {
    Record(int v, int nr, int type) : v(v), nr(nr), type(type){
    }

    bool operator<(const Record &rhs) const {
        if (this->v != rhs.v) {
            return this->v < rhs.v;
        } else if (this->type != rhs.type) {
            return this->type < rhs.type;
        } else {
            if (this->type==0) {
                return this->nr > rhs.nr;
            } else {
                return this->nr < rhs.nr;
            }
        }
    }

    int v;
    int nr;
    int type; //0-begin, 1-end
};

long long int getTopCnt(std::vector<Record> &records, int maximum) {
    int N = records.size()/2;
    std::vector<bool> deleted(N+1, false);
    std::vector<std::pair<int, int> > stack(N+1);
    std::vector<int> cnt(2*N+2, 0);
    std::vector<int> pos(N+1, 0);
    int ssize = 0;
    int maxnr = 0;
    int lastv = 0;
    int cth = 1;
    while ((1<<cth) <= 2*N+10) cth++;
    CoverTree ctree(cth);

    records.emplace_back(0, N, 0);
    records.emplace_back(maximum, N, 1);
    std::sort(records.begin(), records.end());

    for (Record record : records) {
        if (ssize > 0) {
            cnt[stack[ssize-1].second] += record.v - lastv;
        }

        if (record.type == 0) {
            stack[ssize] = std::make_pair(record.nr, ++maxnr);
            pos[record.nr] = ssize;
            ssize++;
        } else {
            deleted[record.nr] = 1;
            ctree.Add(stack[pos[record.nr]].second, maxnr+1, 1);
            while (ssize>0 && deleted[stack[ssize-1].first]) {
                ssize--;
            }
            if (ssize>0 && ctree.Find(stack[ssize-1].second, stack[ssize-1].second+1)>0) {
                stack[ssize-1].second = ++maxnr;
            }
        }

        lastv = record.v;
    }

    int m = 0;
    for (auto &&val : cnt) {
        m = std::max(m, val);
    }

    return (long long int)m;
}


int main() {
    int N, X, Y;
    std::vector<Record> horizontal, vertical;
    scanf("%d %d %d", &N, &X, &Y);

    for (int i=0; i<N; ++i) {
        int x1, y1, x2, y2;
        scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
        horizontal.emplace_back(std::min(x1, x2), i, 0);
        horizontal.emplace_back(std::max(x1, x2), i, 1);
        vertical.emplace_back(std::min(y1, y2), i, 0);
        vertical.emplace_back(std::max(y1, y2), i, 1);
    }

    printf("%lld\n", getTopCnt(horizontal, X) * getTopCnt(vertical, Y));
    return 0;
}