#include <algorithm> #include <iostream> #include <utility> #include <vector> using namespace std; namespace { using ll = long long; struct LenState { private: int len = 0; public: void add(int) { ++len; } void remove(int) { --len; } friend bool operator==(LenState const& lhs, LenState const& rhs) { return lhs.len == rhs.len; } friend bool operator<(LenState const& lhs, LenState const& rhs) { return lhs.len < rhs.len; } friend ostream& operator<<(ostream& os, LenState& rhs) { return os << rhs.len; } }; template <int Mod, int Base> struct HashState { private: int hash = 0; static int base_power(int n) { if (n == 0) return 1; if (n == 1) return Base; int res = base_power(n / 2); res = ll{res} * res % Mod; if (n % 2 == 1) res = ll{res} * Base % Mod; return res; } public: void add(int id) { hash = (hash + base_power(id)) % Mod; } void remove(int id) { hash = (hash + Mod - base_power(id)) % Mod; } friend bool operator==(HashState const& lhs, HashState const& rhs) { return lhs.hash == rhs.hash; } friend bool operator<(HashState const& lhs, HashState const& rhs) { return lhs.hash < rhs.hash; } friend ostream& operator<<(ostream& os, HashState& rhs) { return os << rhs.hash; } }; template <typename... States> struct MultiState; template <> struct MultiState<> { void add(int) { } void remove(int) { } friend bool operator==(MultiState const&, MultiState const&) { return true; } friend bool operator<(MultiState const&, MultiState const&) { return false; } friend ostream& operator<<(ostream& os, MultiState&) { return os; } }; template <typename State, typename... States> struct MultiState<State, States...>: private MultiState<States...> { private: using Parent = MultiState<States...>; Parent& parent() { return *this; } Parent const& parent() const { return *this; } State state; public: void add(int id) { parent().add(id); state.add(id); } void remove(int id) { parent().remove(id); state.remove(id); } friend bool operator==(MultiState const& lhs, MultiState const& rhs) { return lhs.state == rhs.state && lhs.parent() == rhs.parent(); } friend bool operator<(MultiState const& lhs, MultiState const& rhs) { if (lhs.state < rhs.state) return true; if (rhs.state < lhs.state) return false; return lhs.parent() < rhs.parent(); } friend ostream& operator<<(ostream& os, MultiState& rhs) { return os << rhs.state << ' ' << rhs.parent(); } }; using State = MultiState<LenState, HashState<1003162753, 1001>, HashState<1023893771, 1003>>; int solve(vector<pair<int, int>> const& data, int limit) { vector<pair<int, int>> events; events.emplace_back(limit, 0); int n = data.size(); for (int i = 0; i < n; ++i) { int id = i + 1; events.emplace_back(data[i].first, id); events.emplace_back(data[i].second, -id); } sort(events.begin(), events.end()); State state; vector<pair<State, int>> out; { int last = 0; auto i = events.begin(); while (i != events.end()) { auto const& x = i->first; out.emplace_back(state, x - last); while (i != events.end() && i->first == x) { if (i->second < 0) state.remove(-i->second); else if (i->second > 0) state.add(i->second); ++i; } last = x; } } sort(out.begin(), out.end()); int res = 0; { auto i = out.begin(); while (i != out.end()) { auto const& s = i->first; int sum = 0; while (i != out.end() && i->first == s) { sum += i->second; ++i; } res = max(res, sum); } } return res; } } int main() { iostream::sync_with_stdio(false); cin.tie(nullptr); int n, X, Y; cin >> n >> X >> Y; vector<pair<int, int>> xs; xs.reserve(n); vector<pair<int, int>> ys; ys.reserve(n); for (int i = 0; i < n; ++i) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; if (x1 > x2) swap(x1, x2); if (y1 > y2) swap(y1, y2); xs.emplace_back(x1, x2); ys.emplace_back(y1, y2); } auto res = ll{solve(xs, X)} * solve(ys, Y); cout << res << endl; 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 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 | #include <algorithm> #include <iostream> #include <utility> #include <vector> using namespace std; namespace { using ll = long long; struct LenState { private: int len = 0; public: void add(int) { ++len; } void remove(int) { --len; } friend bool operator==(LenState const& lhs, LenState const& rhs) { return lhs.len == rhs.len; } friend bool operator<(LenState const& lhs, LenState const& rhs) { return lhs.len < rhs.len; } friend ostream& operator<<(ostream& os, LenState& rhs) { return os << rhs.len; } }; template <int Mod, int Base> struct HashState { private: int hash = 0; static int base_power(int n) { if (n == 0) return 1; if (n == 1) return Base; int res = base_power(n / 2); res = ll{res} * res % Mod; if (n % 2 == 1) res = ll{res} * Base % Mod; return res; } public: void add(int id) { hash = (hash + base_power(id)) % Mod; } void remove(int id) { hash = (hash + Mod - base_power(id)) % Mod; } friend bool operator==(HashState const& lhs, HashState const& rhs) { return lhs.hash == rhs.hash; } friend bool operator<(HashState const& lhs, HashState const& rhs) { return lhs.hash < rhs.hash; } friend ostream& operator<<(ostream& os, HashState& rhs) { return os << rhs.hash; } }; template <typename... States> struct MultiState; template <> struct MultiState<> { void add(int) { } void remove(int) { } friend bool operator==(MultiState const&, MultiState const&) { return true; } friend bool operator<(MultiState const&, MultiState const&) { return false; } friend ostream& operator<<(ostream& os, MultiState&) { return os; } }; template <typename State, typename... States> struct MultiState<State, States...>: private MultiState<States...> { private: using Parent = MultiState<States...>; Parent& parent() { return *this; } Parent const& parent() const { return *this; } State state; public: void add(int id) { parent().add(id); state.add(id); } void remove(int id) { parent().remove(id); state.remove(id); } friend bool operator==(MultiState const& lhs, MultiState const& rhs) { return lhs.state == rhs.state && lhs.parent() == rhs.parent(); } friend bool operator<(MultiState const& lhs, MultiState const& rhs) { if (lhs.state < rhs.state) return true; if (rhs.state < lhs.state) return false; return lhs.parent() < rhs.parent(); } friend ostream& operator<<(ostream& os, MultiState& rhs) { return os << rhs.state << ' ' << rhs.parent(); } }; using State = MultiState<LenState, HashState<1003162753, 1001>, HashState<1023893771, 1003>>; int solve(vector<pair<int, int>> const& data, int limit) { vector<pair<int, int>> events; events.emplace_back(limit, 0); int n = data.size(); for (int i = 0; i < n; ++i) { int id = i + 1; events.emplace_back(data[i].first, id); events.emplace_back(data[i].second, -id); } sort(events.begin(), events.end()); State state; vector<pair<State, int>> out; { int last = 0; auto i = events.begin(); while (i != events.end()) { auto const& x = i->first; out.emplace_back(state, x - last); while (i != events.end() && i->first == x) { if (i->second < 0) state.remove(-i->second); else if (i->second > 0) state.add(i->second); ++i; } last = x; } } sort(out.begin(), out.end()); int res = 0; { auto i = out.begin(); while (i != out.end()) { auto const& s = i->first; int sum = 0; while (i != out.end() && i->first == s) { sum += i->second; ++i; } res = max(res, sum); } } return res; } } int main() { iostream::sync_with_stdio(false); cin.tie(nullptr); int n, X, Y; cin >> n >> X >> Y; vector<pair<int, int>> xs; xs.reserve(n); vector<pair<int, int>> ys; ys.reserve(n); for (int i = 0; i < n; ++i) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; if (x1 > x2) swap(x1, x2); if (y1 > y2) swap(y1, y2); xs.emplace_back(x1, x2); ys.emplace_back(y1, y2); } auto res = ll{solve(xs, X)} * solve(ys, Y); cout << res << endl; return 0; } |