#include <bits/stdc++.h> using namespace std; #define st first #define nd second #define pb push_back typedef long long ll; typedef double db; typedef long double ldb; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, db> pdd; typedef pair<ldb, ldb> pldd; typedef pair<int, ll> pil; typedef pair<ll, int> pli; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<char> vc; typedef vector<string> vs; typedef vector<db> vdb; typedef vector<ldb> vldb; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<pdd> vpdd; typedef vector<pldd> vpldd; typedef vector<pil> vpil; typedef vector<pli> vpli; template<typename T> void print(T begin, T end, char = ' ', string msg = "", char = '\n'); template<typename It, typename T> void in(It, int, T (*)()); int si (); ll sl (); string ss (int); char sc (); float sf (); db sd (); ldb sld (); void pi (int, char = '\n'); void pl (ll, char = '\n'); void pf (float, char = '\n'); void pc (char, char = '\n'); void pdb (db, char = '\n'); void pldb (ldb, char = '\n'); void ps (string, char = '\n'); template<typename T> void pv (vector<T> v, char = ' ', char = '\n'); ll russian(ll, ll, ll); ll fastpow(ll, ll, ll); ll slowpow(ll, ll, ll); ll _gcd(ll, ll); ll _lcm(ll, ll); ll extgcd(ll, ll, ll&, ll&); ll _inv(ll, ll); const int INF = 1e9; const ll LINF = 1e18; struct Rect { int x1, y1; int x2, y2; }; struct Segment { int x; int id; bool start; bool operator<(const Segment& seg) const { return x < seg.x; } }; const int N = 5e5 + 7; const ll M = 1e17 + 19; const ll B = 31; Rect rects[N]; ll powers[N]; unordered_map<ll, int> inter; int n, rows, cols; ll find(vector<Segment>& segs) { inter.clear(); sort(segs.begin(), segs.end()); ll h = 0; int it = 0; int res = 0; while (it < segs.size()) { int mini = segs[it].x; while (it < segs.size() && segs[it].x == mini) { auto& seg = segs[it]; if (seg.start) h = (h + powers[seg.id]) % M; else h = ((h - powers[seg.id]) % M + M) % M; ++it; } if (it >= segs.size()) break; int maxi = segs[it].x; inter[h] += maxi - mini; res = max(res, inter[h]); } return res; } void read() { n = si(); cols = si(); rows = si(); for (int i = 0; i < n; ++i) { int x1 = si(), y1 = si(); int x2 = si(), y2 = si(); if (x2 < x1) swap(x1, x2); if (y2 < y1) swap(y1, y2); rects[i] = {x1, y1, x2, y2}; } } void solve() { powers[0] = 1; for (int i = 1; i <= n; ++i) powers[i] = (powers[i - 1] * B) % M; vector<Segment> segs; segs.push_back({0, n, true}); segs.push_back({cols, n, false}); for (int i = 0; i < n; ++i) { segs.push_back({rects[i].x1, i, true}); segs.push_back({rects[i].x2, i, false}); } ll x = find(segs); segs.clear(); segs.push_back({0, n, true}); segs.push_back({rows, n, false}); for (int i = 0; i < n; ++i) { segs.push_back({rects[i].y1, i, true}); segs.push_back({rects[i].y2, i, false}); } pl(x * find(segs)); } int main() { read(); solve(); return 0; } template<typename T> string get_token_pointer() { if (is_same<T, int*>::value) return "%d"; if (is_same<T, ll*>::value) return "%lld"; if (is_same<T, char*>::value) return "%c"; if (is_same<T, db*>::value) return "%.8lf"; if (is_same<T, ldb*>::value) return "%.10Lf"; if (is_same<T, float*>::value) return "%.6f"; return "%d"; } template<typename T> string get_token() { if (is_same<T, int>::value) return "%d"; if (is_same<T, ll>::value) return "%lld"; if (is_same<T, char>::value) return "%c"; if (is_same<T, db>::value) return "%.8lf"; if (is_same<T, ldb>::value) return "%.10Lf"; if (is_same<T, float>::value) return "%.6f"; return "%d"; } template<typename It, typename T> void in(It begin, int nn, T (*get)()) { while (nn--) *begin++ = get(); } template <typename T> T scanf_t(string s) { T a; scanf(s.c_str(), &a); return a; } template <typename T> void printf_t(T a, string s, char end_l) { s.push_back(end_l); printf(s.c_str(), a); } // stworzone do tablic tylko template <typename T> void print(T begin, T end, char sep, string msg, char end_l) { if (msg != "") { printf(msg.c_str()); printf("\n"); } string s = get_token_pointer<T>(); s.push_back(sep); while (begin + 1 != end) { printf(s.c_str(), *begin); begin++; } if (begin != end) { s.back() = end_l; printf(s.c_str(), *begin); } } int si () { return scanf_t<int>("%d"); } ll sl () { return scanf_t<ll>("%lld"); } float sf () { return scanf_t<float>("%.6f"); } char sc () { return scanf_t<char>(" %c"); } db sdb () { return scanf_t<db>("%.8lf"); } ldb sldb () { return scanf_t<ldb>("%.10Lf"); } void pi (int a, char end_l) { printf_t<int>(a, "%d", end_l); } void pl (ll a, char end_l) { printf_t<ll>(a, "%lld", end_l); } void pf (float a, char end_l) { printf_t<float>(a, "%.6f", end_l); } void pc (char a, char end_l) { printf_t<char>(a, "%c", end_l); } void pdb (db a, char end_l) { printf_t<db>(a, "%.8lf", end_l); } void pldb (ldb a, char end_l) { printf_t<ldb>(a, "%.10Lf", end_l); } void ps(string a, char end_l) { string s = "%s"; s.push_back(end_l); printf(s.c_str(), a.c_str()); } template<typename T> void pv (vector<T> v, char sep, char end_l) { string s = get_token<T>(); for (size_t i = 0; i < v.size() - 1; ++i) printf_t<T>(v[i], s, sep); if (!v.empty()) printf_t<T>(v.back(), s, end_l); } string ss(int NN) { char T[NN + 7]; scanf("%s", T); return (string)T; } ll fastpow(ll a, ll k, ll m) { ll r = 1LL; while (k) { if (k & 1LL) r = (r * a) % m; a = (a * a) % m; k >>= 1LL; } return r; } ll slowpow(ll a, ll k, ll m) { ll r = 1LL; while (k) { if (k & 1LL) r = russian(r, a, m); a = russian(a, a, m); k >>= 1LL; } return r; } ll russian(ll a, ll k, ll m) { ll r = 0LL; while (k) { if (k & 1LL) r = (r + a) % m; a = (a + a) % m; k >>= 1LL; } return r; } ll _gcd(ll a, ll b) { while (b) swap(a %= b, b); return a; } ll _lcm(ll a, ll b) { return a / _gcd(a, b) * b; } ll extgcd(ll a, ll b, ll& k, ll& l) { if (b == 0) { k = 1; l = 0; return a; } ll res = extgcd(b, a % b, l, k); l -= a / b * k; return res; } ll _inv(ll a, ll p) { return fastpow(a, p - 2, p); }
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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | #include <bits/stdc++.h> using namespace std; #define st first #define nd second #define pb push_back typedef long long ll; typedef double db; typedef long double ldb; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, db> pdd; typedef pair<ldb, ldb> pldd; typedef pair<int, ll> pil; typedef pair<ll, int> pli; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<char> vc; typedef vector<string> vs; typedef vector<db> vdb; typedef vector<ldb> vldb; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<pdd> vpdd; typedef vector<pldd> vpldd; typedef vector<pil> vpil; typedef vector<pli> vpli; template<typename T> void print(T begin, T end, char = ' ', string msg = "", char = '\n'); template<typename It, typename T> void in(It, int, T (*)()); int si (); ll sl (); string ss (int); char sc (); float sf (); db sd (); ldb sld (); void pi (int, char = '\n'); void pl (ll, char = '\n'); void pf (float, char = '\n'); void pc (char, char = '\n'); void pdb (db, char = '\n'); void pldb (ldb, char = '\n'); void ps (string, char = '\n'); template<typename T> void pv (vector<T> v, char = ' ', char = '\n'); ll russian(ll, ll, ll); ll fastpow(ll, ll, ll); ll slowpow(ll, ll, ll); ll _gcd(ll, ll); ll _lcm(ll, ll); ll extgcd(ll, ll, ll&, ll&); ll _inv(ll, ll); const int INF = 1e9; const ll LINF = 1e18; struct Rect { int x1, y1; int x2, y2; }; struct Segment { int x; int id; bool start; bool operator<(const Segment& seg) const { return x < seg.x; } }; const int N = 5e5 + 7; const ll M = 1e17 + 19; const ll B = 31; Rect rects[N]; ll powers[N]; unordered_map<ll, int> inter; int n, rows, cols; ll find(vector<Segment>& segs) { inter.clear(); sort(segs.begin(), segs.end()); ll h = 0; int it = 0; int res = 0; while (it < segs.size()) { int mini = segs[it].x; while (it < segs.size() && segs[it].x == mini) { auto& seg = segs[it]; if (seg.start) h = (h + powers[seg.id]) % M; else h = ((h - powers[seg.id]) % M + M) % M; ++it; } if (it >= segs.size()) break; int maxi = segs[it].x; inter[h] += maxi - mini; res = max(res, inter[h]); } return res; } void read() { n = si(); cols = si(); rows = si(); for (int i = 0; i < n; ++i) { int x1 = si(), y1 = si(); int x2 = si(), y2 = si(); if (x2 < x1) swap(x1, x2); if (y2 < y1) swap(y1, y2); rects[i] = {x1, y1, x2, y2}; } } void solve() { powers[0] = 1; for (int i = 1; i <= n; ++i) powers[i] = (powers[i - 1] * B) % M; vector<Segment> segs; segs.push_back({0, n, true}); segs.push_back({cols, n, false}); for (int i = 0; i < n; ++i) { segs.push_back({rects[i].x1, i, true}); segs.push_back({rects[i].x2, i, false}); } ll x = find(segs); segs.clear(); segs.push_back({0, n, true}); segs.push_back({rows, n, false}); for (int i = 0; i < n; ++i) { segs.push_back({rects[i].y1, i, true}); segs.push_back({rects[i].y2, i, false}); } pl(x * find(segs)); } int main() { read(); solve(); return 0; } template<typename T> string get_token_pointer() { if (is_same<T, int*>::value) return "%d"; if (is_same<T, ll*>::value) return "%lld"; if (is_same<T, char*>::value) return "%c"; if (is_same<T, db*>::value) return "%.8lf"; if (is_same<T, ldb*>::value) return "%.10Lf"; if (is_same<T, float*>::value) return "%.6f"; return "%d"; } template<typename T> string get_token() { if (is_same<T, int>::value) return "%d"; if (is_same<T, ll>::value) return "%lld"; if (is_same<T, char>::value) return "%c"; if (is_same<T, db>::value) return "%.8lf"; if (is_same<T, ldb>::value) return "%.10Lf"; if (is_same<T, float>::value) return "%.6f"; return "%d"; } template<typename It, typename T> void in(It begin, int nn, T (*get)()) { while (nn--) *begin++ = get(); } template <typename T> T scanf_t(string s) { T a; scanf(s.c_str(), &a); return a; } template <typename T> void printf_t(T a, string s, char end_l) { s.push_back(end_l); printf(s.c_str(), a); } // stworzone do tablic tylko template <typename T> void print(T begin, T end, char sep, string msg, char end_l) { if (msg != "") { printf(msg.c_str()); printf("\n"); } string s = get_token_pointer<T>(); s.push_back(sep); while (begin + 1 != end) { printf(s.c_str(), *begin); begin++; } if (begin != end) { s.back() = end_l; printf(s.c_str(), *begin); } } int si () { return scanf_t<int>("%d"); } ll sl () { return scanf_t<ll>("%lld"); } float sf () { return scanf_t<float>("%.6f"); } char sc () { return scanf_t<char>(" %c"); } db sdb () { return scanf_t<db>("%.8lf"); } ldb sldb () { return scanf_t<ldb>("%.10Lf"); } void pi (int a, char end_l) { printf_t<int>(a, "%d", end_l); } void pl (ll a, char end_l) { printf_t<ll>(a, "%lld", end_l); } void pf (float a, char end_l) { printf_t<float>(a, "%.6f", end_l); } void pc (char a, char end_l) { printf_t<char>(a, "%c", end_l); } void pdb (db a, char end_l) { printf_t<db>(a, "%.8lf", end_l); } void pldb (ldb a, char end_l) { printf_t<ldb>(a, "%.10Lf", end_l); } void ps(string a, char end_l) { string s = "%s"; s.push_back(end_l); printf(s.c_str(), a.c_str()); } template<typename T> void pv (vector<T> v, char sep, char end_l) { string s = get_token<T>(); for (size_t i = 0; i < v.size() - 1; ++i) printf_t<T>(v[i], s, sep); if (!v.empty()) printf_t<T>(v.back(), s, end_l); } string ss(int NN) { char T[NN + 7]; scanf("%s", T); return (string)T; } ll fastpow(ll a, ll k, ll m) { ll r = 1LL; while (k) { if (k & 1LL) r = (r * a) % m; a = (a * a) % m; k >>= 1LL; } return r; } ll slowpow(ll a, ll k, ll m) { ll r = 1LL; while (k) { if (k & 1LL) r = russian(r, a, m); a = russian(a, a, m); k >>= 1LL; } return r; } ll russian(ll a, ll k, ll m) { ll r = 0LL; while (k) { if (k & 1LL) r = (r + a) % m; a = (a + a) % m; k >>= 1LL; } return r; } ll _gcd(ll a, ll b) { while (b) swap(a %= b, b); return a; } ll _lcm(ll a, ll b) { return a / _gcd(a, b) * b; } ll extgcd(ll a, ll b, ll& k, ll& l) { if (b == 0) { k = 1; l = 0; return a; } ll res = extgcd(b, a % b, l, k); l -= a / b * k; return res; } ll _inv(ll a, ll p) { return fastpow(a, p - 2, p); } |