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

#pragma warning (disable : 4996)

using namespace std;

typedef unsigned long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef pair<pLL,pLL> ppLLpLL;
typedef vector<LL> vL;
typedef vector<int> vi;
typedef vector<pii> vpii;

class RSQ 
{
private:
	vL data;
	int sz;
	void addRangePrivate(int idx, int qLeft, int qAfterRight, int rLeft, int rAfterRight, LL val) {
		if(qLeft==rLeft && qAfterRight==rAfterRight) {
			data[idx] += val;
		} else {
			int mid = (rLeft + rAfterRight) / 2;
			if(qAfterRight <= mid) {
				addRangePrivate(2*idx, qLeft, qAfterRight, rLeft, mid, val);
			} else if(qLeft >= mid) {
				addRangePrivate(2*idx+1, qLeft, qAfterRight, mid, rAfterRight, val);
			} else {
				addRangePrivate(2*idx, qLeft, mid, rLeft, mid, val);
				addRangePrivate(2*idx+1, mid, qAfterRight, mid, rAfterRight, val);
			}
		}
	}
public:
	RSQ(int n) {
		sz = 8;
		while(sz < n) {
			sz *= 2;
		}
		data.assign(2*sz, 0uLL);
	}
	void addRange(int start, int afterEnd, LL val) {
		addRangePrivate(1, start, afterEnd, 0, sz, val);
	}
	void finalizeAllAdds(void) {
		for(int i=1; i<sz; i++) {
			data[2*i] += data[i];
			data[2*i+1] += data[i];
			data[i] = 0LL;
		}
	}
	inline LL get(int idx) const {
		return data[idx + sz];
	}
};

vi buildSortedNoRepeats(const vpii &coords, int Sz) 
{
	vi temp;
	temp.reserve(coords.size() * 2);
	for(size_t k=0; k<coords.size(); k++) {
		temp.push_back(coords[k].first);
		temp.push_back(coords[k].second);
	}
	temp.push_back(0);
	temp.push_back(Sz);
	sort(temp.begin(), temp.end());
	vi res;
	res.reserve(temp.size());
	res.push_back(temp[0]);
	for(size_t k=1; k < temp.size(); k++) {
		if(temp[k] > temp[k-1]) {
			res.push_back(temp[k]);
		}
	}
	return res;
}

int calc_all(vpii &coords, int Sz) {
	vi coordsSortedNoRepeats = buildSortedNoRepeats(coords, Sz);
	for(size_t k=0; k<coords.size(); k++) {
		coords[k].first = lower_bound(coordsSortedNoRepeats.begin(), coordsSortedNoRepeats.end(), coords[k].first) - coordsSortedNoRepeats.begin();
		coords[k].second = lower_bound(coordsSortedNoRepeats.begin(), coordsSortedNoRepeats.end(), coords[k].second) - coordsSortedNoRepeats.begin();
	}
	vector<RSQ> the_rsq(4, RSQ(coordsSortedNoRepeats.size()));
	LL hash_low = 0LL, hash_high = 0LL;
	LL max_low = (1LL << 23) / coords.size();
	max_low += max_low / 2;
	LL max_high = (1LL << 23) / coords.size();
	for(int hash_idx=0; hash_idx<4; hash_idx++) {
		for(size_t k=0; k<coords.size(); k++) {
			hash_low += (rand() % max_low) + 1;
			hash_high += ((rand() % max_high) + 1) << 23;
			the_rsq[hash_idx].addRange(coords[k].first, coords[k].second, hash_high);
			if(coords[k].first > 0) {
				the_rsq[hash_idx].addRange(0, coords[k].first, hash_low);
			}
			the_rsq[hash_idx].addRange(coords[k].second, coordsSortedNoRepeats.size()-1, hash_low);
		}
		the_rsq[hash_idx].finalizeAllAdds();
	}
	map<ppLLpLL, int> how_much;
	for(size_t k=0; k+1<coordsSortedNoRepeats.size(); k++)
		how_much[make_pair(make_pair(the_rsq[0].get(k),the_rsq[1].get(k)),make_pair(the_rsq[2].get(k),the_rsq[3].get(k)))] += coordsSortedNoRepeats[k+1] - coordsSortedNoRepeats[k];
	int res = 0;
	for(map<ppLLpLL, int>::iterator it = how_much.begin(); it != how_much.end(); it++) {
		if(it->second > res)
			res = it->second;
	}
	return res;
}

int main(int argc, char* argv[])
{
	srand(17127);
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
#endif
	int n;
	int ISz, JSz;
	scanf("%d %d %d", &n, &ISz, &JSz);
	vpii icoords(n), jcoords(n);
	for(int k=0; k<n; k++) {
		scanf("%d %d %d %d", &(icoords[k].first), &(jcoords[k].first), &(icoords[k].second), &(jcoords[k].second));
		if(icoords[k].first > icoords[k].second)
			swap(icoords[k].first, icoords[k].second);
		if(jcoords[k].first > jcoords[k].second)
			swap(jcoords[k].first, jcoords[k].second);
	}
	cout << (LL)calc_all(icoords, ISz) * (LL)calc_all(jcoords, JSz) << endl;
	return 0;
}