#include <bits/stdc++.h> using namespace std; void unify(vector <int> &vec) { sort(vec.begin(), vec.end()); vec.resize(unique(vec.begin(), vec.end()) - vec.begin()); } int mapDown(int x, const vector <int> &values) { return lower_bound(values.begin(), values.end(), x) - values.begin(); } struct MaxCountTree { typedef pair <int,int> val_t; typedef int mod_t; val_t sum(const val_t &a, const val_t &b) { if (a.first != b.first) { return max(a, b); } else { return {a.first, a.second + b.second}; } } val_t getValInit(int i) { int len = i < lengths.size() ? lengths[i] : 0; return {0, len}; } int p = 1; vector <val_t> V; vector <mod_t> M; vector <int> lengths; MaxCountTree(int n, const vector <int> &lengths): lengths(lengths) { while (p < n) p *= 2; int m = 2 * p - 1; V.resize(m); M.resize(m, 0); for (int i = p - 1; i < m; i++) { V[i] = getValInit(i - p + 1); } for (int i = p - 2; i >= 0; i--) { V[i] = sum(V[2 * i + 1], V[2 * i + 2]); } } void modify(int x, int y, const mod_t &m) { _modify(0, 0, p-1, x, y, m); } val_t query() { _push(0); return V[0]; } void _push(int u) { V[u].first += M[u]; if (u < p-1) { M[2 * u + 1] += M[u]; M[2 * u + 2] += M[u]; } M[u] = 0; } void _modify(int u, int a, int b, int x, int y, const mod_t &m) { _push(u); if (x <= a && b <= y) { M[u] += m; _push(u); return ; } int mid = (a + b) / 2; if (x <= mid) _modify(2 * u + 1, a, mid, x, y, m); else _push(2 * u + 1); if (mid < y) _modify(2 * u + 2, mid + 1, b, x, y, m); else _push(2 * u + 2); V[u] = sum(V[2 * u + 1], V[2 * u + 2]); } }; long long solve1D(int n, int xMax, vector <int> &lx, vector <int> &rx) { vector <int> cuts = {0, xMax}; copy(lx.begin(), lx.end(), back_inserter(cuts)); copy(rx.begin(), rx.end(), back_inserter(cuts)); unify(cuts); int m = cuts.size() - 1; vector <int> lengths(m); for (int i = 0; i < m; i++) { lengths[i] = cuts[i + 1] - cuts[i]; } for (int i = 0; i < n; i++) { lx[i] = mapDown(lx[i], cuts); rx[i] = mapDown(rx[i], cuts) - 1; } struct event { pair <int,int> range; int change; }; vector <vector<event>> events(m + 1); vector <int> mod(m + 1, 0); for (int i = 0; i < n; i++) { pair <int,int> range = {lx[i], rx[i]}; mod[0] += 1; events[0].push_back({range, -1}); mod[lx[i]] -= 1; events[lx[i]].push_back({range, 2}); mod[rx[i] + 1] += 1; events[rx[i] + 1].push_back({range, -2}); } MaxCountTree tree(m, lengths); int ans = 0; int modFull = 0; for (int pos = 0; pos < m; pos++) { modFull += mod[pos]; for (auto &e : events[pos]) { int l, r; tie(l, r) = e.range; tree.modify(l, r, e.change); } auto q = tree.query(); if (q.first + modFull == n) { ans = max(ans, q.second); } } return ans; } int main() { ios_base::sync_with_stdio(false); int n, xMax, yMax; cin >> n >> xMax >> yMax; vector <int> lx(n), rx(n), ly(n), ry(n); for (int i = 0; i < n; i++) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; lx[i] = min(x1, x2); rx[i] = max(x1, x2); ly[i] = min(y1, y2); ry[i] = max(y1, y2); } long long ans = solve1D(n, xMax, lx, rx) * solve1D(n, yMax, ly, ry); cout << ans; return 0; }
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 | #include <bits/stdc++.h> using namespace std; void unify(vector <int> &vec) { sort(vec.begin(), vec.end()); vec.resize(unique(vec.begin(), vec.end()) - vec.begin()); } int mapDown(int x, const vector <int> &values) { return lower_bound(values.begin(), values.end(), x) - values.begin(); } struct MaxCountTree { typedef pair <int,int> val_t; typedef int mod_t; val_t sum(const val_t &a, const val_t &b) { if (a.first != b.first) { return max(a, b); } else { return {a.first, a.second + b.second}; } } val_t getValInit(int i) { int len = i < lengths.size() ? lengths[i] : 0; return {0, len}; } int p = 1; vector <val_t> V; vector <mod_t> M; vector <int> lengths; MaxCountTree(int n, const vector <int> &lengths): lengths(lengths) { while (p < n) p *= 2; int m = 2 * p - 1; V.resize(m); M.resize(m, 0); for (int i = p - 1; i < m; i++) { V[i] = getValInit(i - p + 1); } for (int i = p - 2; i >= 0; i--) { V[i] = sum(V[2 * i + 1], V[2 * i + 2]); } } void modify(int x, int y, const mod_t &m) { _modify(0, 0, p-1, x, y, m); } val_t query() { _push(0); return V[0]; } void _push(int u) { V[u].first += M[u]; if (u < p-1) { M[2 * u + 1] += M[u]; M[2 * u + 2] += M[u]; } M[u] = 0; } void _modify(int u, int a, int b, int x, int y, const mod_t &m) { _push(u); if (x <= a && b <= y) { M[u] += m; _push(u); return ; } int mid = (a + b) / 2; if (x <= mid) _modify(2 * u + 1, a, mid, x, y, m); else _push(2 * u + 1); if (mid < y) _modify(2 * u + 2, mid + 1, b, x, y, m); else _push(2 * u + 2); V[u] = sum(V[2 * u + 1], V[2 * u + 2]); } }; long long solve1D(int n, int xMax, vector <int> &lx, vector <int> &rx) { vector <int> cuts = {0, xMax}; copy(lx.begin(), lx.end(), back_inserter(cuts)); copy(rx.begin(), rx.end(), back_inserter(cuts)); unify(cuts); int m = cuts.size() - 1; vector <int> lengths(m); for (int i = 0; i < m; i++) { lengths[i] = cuts[i + 1] - cuts[i]; } for (int i = 0; i < n; i++) { lx[i] = mapDown(lx[i], cuts); rx[i] = mapDown(rx[i], cuts) - 1; } struct event { pair <int,int> range; int change; }; vector <vector<event>> events(m + 1); vector <int> mod(m + 1, 0); for (int i = 0; i < n; i++) { pair <int,int> range = {lx[i], rx[i]}; mod[0] += 1; events[0].push_back({range, -1}); mod[lx[i]] -= 1; events[lx[i]].push_back({range, 2}); mod[rx[i] + 1] += 1; events[rx[i] + 1].push_back({range, -2}); } MaxCountTree tree(m, lengths); int ans = 0; int modFull = 0; for (int pos = 0; pos < m; pos++) { modFull += mod[pos]; for (auto &e : events[pos]) { int l, r; tie(l, r) = e.range; tree.modify(l, r, e.change); } auto q = tree.query(); if (q.first + modFull == n) { ans = max(ans, q.second); } } return ans; } int main() { ios_base::sync_with_stdio(false); int n, xMax, yMax; cin >> n >> xMax >> yMax; vector <int> lx(n), rx(n), ly(n), ry(n); for (int i = 0; i < n; i++) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; lx[i] = min(x1, x2); rx[i] = max(x1, x2); ly[i] = min(y1, y2); ry[i] = max(y1, y2); } long long ans = solve1D(n, xMax, lx, rx) * solve1D(n, yMax, ly, ry); cout << ans; return 0; } |