#include <bits/stdc++.h> using namespace std; long long n, X, Y; struct event { long long index, segment; bool type; // 1 - otwarcie, 0 - zamknięcie event() {} event(const long long& a, const long long& s, const bool& b) : index(a), segment(s), type(b) {} bool operator<(const event& a) { return index == a.index ? type < a.type : index < a.index; } }; long long solve(vector<event>& v) { sort(v.begin(), v.end()); map<vector<bool>, long long> m; vector<bool> touch(2 * n, false); long long amount = 0, begin = 0; for (event& i : v) { if (i.type) { touch[i.segment] = true; ++amount; begin = i.index; } else { if (amount == n) m[touch] += i.index - begin; touch[i.segment] = false; --amount; } } long long odp = 0; for (auto& i : m) odp = odp < i.second ? i.second : odp; return odp; } int main() { cin >> n >> X >> Y; vector<event> vertical, horizontal; for (long long i = 0; i < n; i++) { long long x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; if (y1 > y2) swap(y1, y2); if (x1 > x2) swap(x1, x2); vertical.push_back(event(0, n + i, 1)); vertical.push_back(event(y1, n + i, 0)); vertical.push_back(event(y1, i, 1)); vertical.push_back(event(y2, i, 0)); vertical.push_back(event(y2, n + i, 1)); horizontal.push_back(event(0, n + i, 1)); horizontal.push_back(event(x1, n + i, 0)); horizontal.push_back(event(x1, i, 1)); horizontal.push_back(event(x2, i, 0)); horizontal.push_back(event(x2, n + i, 1)); } cout << solve(vertical) * solve(horizontal) << '\n'; }
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 | #include <bits/stdc++.h> using namespace std; long long n, X, Y; struct event { long long index, segment; bool type; // 1 - otwarcie, 0 - zamknięcie event() {} event(const long long& a, const long long& s, const bool& b) : index(a), segment(s), type(b) {} bool operator<(const event& a) { return index == a.index ? type < a.type : index < a.index; } }; long long solve(vector<event>& v) { sort(v.begin(), v.end()); map<vector<bool>, long long> m; vector<bool> touch(2 * n, false); long long amount = 0, begin = 0; for (event& i : v) { if (i.type) { touch[i.segment] = true; ++amount; begin = i.index; } else { if (amount == n) m[touch] += i.index - begin; touch[i.segment] = false; --amount; } } long long odp = 0; for (auto& i : m) odp = odp < i.second ? i.second : odp; return odp; } int main() { cin >> n >> X >> Y; vector<event> vertical, horizontal; for (long long i = 0; i < n; i++) { long long x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; if (y1 > y2) swap(y1, y2); if (x1 > x2) swap(x1, x2); vertical.push_back(event(0, n + i, 1)); vertical.push_back(event(y1, n + i, 0)); vertical.push_back(event(y1, i, 1)); vertical.push_back(event(y2, i, 0)); vertical.push_back(event(y2, n + i, 1)); horizontal.push_back(event(0, n + i, 1)); horizontal.push_back(event(x1, n + i, 0)); horizontal.push_back(event(x1, i, 1)); horizontal.push_back(event(x2, i, 0)); horizontal.push_back(event(x2, n + i, 1)); } cout << solve(vertical) * solve(horizontal) << '\n'; } |