#include <stdio.h> #include <assert.h> #include <random> #include <vector> #include <map> #include <algorithm> long long h[500000]; int find_max(const std::vector<std::pair<int, int>> &v, int max_indx) { int last = 0; long long hash = 0LL; std::map<long long, int> mp; for (int i = 0; i < v.size(); i++) { int xi = v[i].first; int indx = v[i].second; mp[hash] += xi - last; hash = hash ^ h[indx]; last = xi; } //assert(hash == 0); mp[hash] += max_indx - last; int answer = 0; for(auto p : mp) if (answer < p.second) answer = p.second; return answer; } int main() { int n, X, Y; long long seed = 26236213810800LL; std::vector<std::pair<int, int>> x_p; std::vector<std::pair<int, int>> y_p; scanf("%d%d%d", &n, &X, &Y); for (int i = 0; i < n; i++) { int x1, y1, x2, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2); seed += x1 + x2 + y1 + y2; x_p.push_back(std::make_pair(x1, i)); x_p.push_back(std::make_pair(x2, i)); y_p.push_back(std::make_pair(y1, i)); y_p.push_back(std::make_pair(y2, i)); } std::mt19937_64 gen(seed); for (int i = 0; i < n; i++) h[i] = gen(); std::sort(x_p.begin(), x_p.end()); std::sort(y_p.begin(), y_p.end()); int max_x = find_max(x_p, X); int max_y = find_max(y_p, Y); printf("%lld\n", (long long)max_x * max_y); 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 | #include <stdio.h> #include <assert.h> #include <random> #include <vector> #include <map> #include <algorithm> long long h[500000]; int find_max(const std::vector<std::pair<int, int>> &v, int max_indx) { int last = 0; long long hash = 0LL; std::map<long long, int> mp; for (int i = 0; i < v.size(); i++) { int xi = v[i].first; int indx = v[i].second; mp[hash] += xi - last; hash = hash ^ h[indx]; last = xi; } //assert(hash == 0); mp[hash] += max_indx - last; int answer = 0; for(auto p : mp) if (answer < p.second) answer = p.second; return answer; } int main() { int n, X, Y; long long seed = 26236213810800LL; std::vector<std::pair<int, int>> x_p; std::vector<std::pair<int, int>> y_p; scanf("%d%d%d", &n, &X, &Y); for (int i = 0; i < n; i++) { int x1, y1, x2, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2); seed += x1 + x2 + y1 + y2; x_p.push_back(std::make_pair(x1, i)); x_p.push_back(std::make_pair(x2, i)); y_p.push_back(std::make_pair(y1, i)); y_p.push_back(std::make_pair(y2, i)); } std::mt19937_64 gen(seed); for (int i = 0; i < n; i++) h[i] = gen(); std::sort(x_p.begin(), x_p.end()); std::sort(y_p.begin(), y_p.end()); int max_x = find_max(x_p, X); int max_y = find_max(y_p, Y); printf("%lld\n", (long long)max_x * max_y); return 0; } |