#include <bits/stdc++.h> using namespace std; typedef long long int lli; typedef pair<lli, lli> par; #define st first #define nd second lli solve(vector<par> &v, lli lim) { lli state = 0, prev = 0; map<lli, lli> res; sort(v.begin(), v.end()); prev = v.back().st - lim; for (int i=0; i<(int)v.size(); i++) { lli len = v[i].st-prev; res[state] += len; prev = v[i].st; for (int j=i; j<(int)v.size(); j++) { if (v[i].st != v[j].st) break; state += v[j].nd; i = j; } } lli w = 0; for (const auto &p : res) { w = max(w, p.nd); } return w; } vector<par> v1, v2; int main() { srand(time(0)); lli n, X, Y; scanf("%lld%lld%lld", &n, &X, &Y); for (int i=0; i<n; i++) { lli a, b, c, d; scanf("%lld%lld%lld%lld", &a, &b, &c, &d); lli tmp = rand()*rand(); v1.push_back({a, tmp}); v1.push_back({c, -tmp}); v2.push_back({b, tmp}); v2.push_back({d, -tmp}); } printf("%lld\n", solve(v1, X)*solve(v2, 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 | #include <bits/stdc++.h> using namespace std; typedef long long int lli; typedef pair<lli, lli> par; #define st first #define nd second lli solve(vector<par> &v, lli lim) { lli state = 0, prev = 0; map<lli, lli> res; sort(v.begin(), v.end()); prev = v.back().st - lim; for (int i=0; i<(int)v.size(); i++) { lli len = v[i].st-prev; res[state] += len; prev = v[i].st; for (int j=i; j<(int)v.size(); j++) { if (v[i].st != v[j].st) break; state += v[j].nd; i = j; } } lli w = 0; for (const auto &p : res) { w = max(w, p.nd); } return w; } vector<par> v1, v2; int main() { srand(time(0)); lli n, X, Y; scanf("%lld%lld%lld", &n, &X, &Y); for (int i=0; i<n; i++) { lli a, b, c, d; scanf("%lld%lld%lld%lld", &a, &b, &c, &d); lli tmp = rand()*rand(); v1.push_back({a, tmp}); v1.push_back({c, -tmp}); v2.push_back({b, tmp}); v2.push_back({d, -tmp}); } printf("%lld\n", solve(v1, X)*solve(v2, Y)); return 0; } |