#include<iostream> #include<assert.h> #include<cstdio> #include<string> #include<cmath> #include<bitset> #include<vector> #include<map> #include<set> #include<algorithm> #include<unordered_map> #include<utility> using namespace std; int SolveOneDimension( const std::vector<std::pair<int, int>> &lines, int boundary, std::vector<long long>& labels) { std::unordered_map<long long, int> regions; long long hash = 0; int prev = 0; for (auto l: lines) { regions[hash] += l.first - prev; prev = l.first; hash += labels[l.second]; labels[l.second] *= -1; } regions[hash] += boundary - prev; int max_region = 0; for (auto& [k, v]: regions) { max_region = std::max(max_region, v); } return max_region; } void Solve() { int n, X, Y; std::cin >> n >> X >> Y; std::vector<long long> labels(n + 1); for (int i = 0; i < n; i++) { labels[i] = (long long)(rand() % 10000) * (rand() % 10000) * (rand() % 10000) + (rand() % 1000000); } std::vector<std::pair<int, int>> horizontal, vertical; for (int i = 0; i < n; i++) { int x1, y1, x2, y2; std::cin >> x1 >> y1 >> x2 >> y2; horizontal.push_back({std::min(x1, x2), i}); horizontal.push_back({std::max(x1, x2), i}); vertical.push_back({std::min(y1, y2), i}); vertical.push_back({std::max(y1, y2), i}); } std::sort(horizontal.begin(), horizontal.end()); std::sort(vertical.begin(), vertical.end()); int max_h = SolveOneDimension(horizontal, X, labels); int max_v = SolveOneDimension(vertical, Y, labels); std::cout << (long long)max_h * max_v << '\n'; } int main() { std::ios::sync_with_stdio(false); Solve(); 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 | #include<iostream> #include<assert.h> #include<cstdio> #include<string> #include<cmath> #include<bitset> #include<vector> #include<map> #include<set> #include<algorithm> #include<unordered_map> #include<utility> using namespace std; int SolveOneDimension( const std::vector<std::pair<int, int>> &lines, int boundary, std::vector<long long>& labels) { std::unordered_map<long long, int> regions; long long hash = 0; int prev = 0; for (auto l: lines) { regions[hash] += l.first - prev; prev = l.first; hash += labels[l.second]; labels[l.second] *= -1; } regions[hash] += boundary - prev; int max_region = 0; for (auto& [k, v]: regions) { max_region = std::max(max_region, v); } return max_region; } void Solve() { int n, X, Y; std::cin >> n >> X >> Y; std::vector<long long> labels(n + 1); for (int i = 0; i < n; i++) { labels[i] = (long long)(rand() % 10000) * (rand() % 10000) * (rand() % 10000) + (rand() % 1000000); } std::vector<std::pair<int, int>> horizontal, vertical; for (int i = 0; i < n; i++) { int x1, y1, x2, y2; std::cin >> x1 >> y1 >> x2 >> y2; horizontal.push_back({std::min(x1, x2), i}); horizontal.push_back({std::max(x1, x2), i}); vertical.push_back({std::min(y1, y2), i}); vertical.push_back({std::max(y1, y2), i}); } std::sort(horizontal.begin(), horizontal.end()); std::sort(vertical.begin(), vertical.end()); int max_h = SolveOneDimension(horizontal, X, labels); int max_v = SolveOneDimension(vertical, Y, labels); std::cout << (long long)max_h * max_v << '\n'; } int main() { std::ios::sync_with_stdio(false); Solve(); return 0; } |