#include <iostream> #include <map> #include <unordered_map> #include <random> #include <algorithm> #include <ctime> using Q = std::multimap<int, int>; int processDir(Q &points, int n, int len) { std::vector<unsigned long long> changers(n); { std::default_random_engine d(std::time(NULL)); std::uniform_int_distribution<unsigned long long> dist(1); std::generate(changers.begin(), changers.end(), [&]() { return dist(d); }); } int last = 0; unsigned long long state = 0; std::unordered_map<unsigned long long, int> counts; for (auto &p: points) { counts[state] += p.first - last; last = p.first; state ^= changers[p.second]; } counts[state] += len - last; return std::max_element(counts.begin(), counts.end(), [](auto &l, auto &r) { return l.second < r.second; })->second; } int main() { int n, w, h; std::cin >> n >> w >> h; Q hQ, vQ; for (int i = 0; i < n; ++i) { int x1, y1, x2, y2; std::cin >> x1 >> y1 >> x2 >> y2; hQ.emplace(x1, i); hQ.emplace(x2, i); vQ.emplace(y1, i); vQ.emplace(y2, i); } long long hR = processDir(hQ, n, w); long long vR = processDir(vQ, n, h); std::cout << hR * vR << "\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 | #include <iostream> #include <map> #include <unordered_map> #include <random> #include <algorithm> #include <ctime> using Q = std::multimap<int, int>; int processDir(Q &points, int n, int len) { std::vector<unsigned long long> changers(n); { std::default_random_engine d(std::time(NULL)); std::uniform_int_distribution<unsigned long long> dist(1); std::generate(changers.begin(), changers.end(), [&]() { return dist(d); }); } int last = 0; unsigned long long state = 0; std::unordered_map<unsigned long long, int> counts; for (auto &p: points) { counts[state] += p.first - last; last = p.first; state ^= changers[p.second]; } counts[state] += len - last; return std::max_element(counts.begin(), counts.end(), [](auto &l, auto &r) { return l.second < r.second; })->second; } int main() { int n, w, h; std::cin >> n >> w >> h; Q hQ, vQ; for (int i = 0; i < n; ++i) { int x1, y1, x2, y2; std::cin >> x1 >> y1 >> x2 >> y2; hQ.emplace(x1, i); hQ.emplace(x2, i); vQ.emplace(y1, i); vQ.emplace(y2, i); } long long hR = processDir(hQ, n, w); long long vR = processDir(vQ, n, h); std::cout << hR * vR << "\n"; } |