#include <bits/stdc++.h> using namespace std; int calc(int m, multiset<int> & from, multiset<int> & to, multiset<pair<int, int> > & bans) { int s1 = 0; int s2 = m; if (!from.empty()) { s1 = *from.rbegin(); s2 = *to.begin(); if (s2 <= s1) { return 0; } } int ans = 0; int banto = s1; for (auto p : bans) { int b1 = p.first; if (b1 >= s2) { break; } int b2 = p.second; if (b1 > banto) { ans += b1 - banto; } banto = max(banto, b2); } // do [banto, s2] if (s2 > banto) { ans += s2 - banto; } return ans; } int solve(int m, vector<pair<int, int> > & v) { int n = v.size(); vector<pair<int, int> > events; for (auto p : v) { events.push_back(p); events.push_back({p.second, p.first}); } sort(events.begin(), events.end()); multiset<int> from; multiset<int> to; multiset<pair<int, int> > bans; for (auto p : v) { bans.insert(p); } int ans = calc(m, from, to, bans); for (auto e : events) { if (e.first < e.second) { bans.erase(bans.find(e)); from.insert(e.first); to.insert(e.second); } else { to.erase(to.find(e.first)); from.erase(from.find(e.second)); bans.insert({e.second, e.first}); } int cand = calc(m, from, to, bans); ans = max(ans, cand); } return ans; } int main() { ios_base::sync_with_stdio(false); cout.precision(15); cout << fixed; cin.tie(0); int n, x, y; cin >> n >> x >> y; vector<pair<int, int> > xx; vector<pair<int, int> > yy; 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); xx.push_back({x1, x2}); yy.push_back({y1, y2}); } long long ansx = solve(x, xx); long long ansy = solve(y, yy); cout << ansx * ansy << 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 | #include <bits/stdc++.h> using namespace std; int calc(int m, multiset<int> & from, multiset<int> & to, multiset<pair<int, int> > & bans) { int s1 = 0; int s2 = m; if (!from.empty()) { s1 = *from.rbegin(); s2 = *to.begin(); if (s2 <= s1) { return 0; } } int ans = 0; int banto = s1; for (auto p : bans) { int b1 = p.first; if (b1 >= s2) { break; } int b2 = p.second; if (b1 > banto) { ans += b1 - banto; } banto = max(banto, b2); } // do [banto, s2] if (s2 > banto) { ans += s2 - banto; } return ans; } int solve(int m, vector<pair<int, int> > & v) { int n = v.size(); vector<pair<int, int> > events; for (auto p : v) { events.push_back(p); events.push_back({p.second, p.first}); } sort(events.begin(), events.end()); multiset<int> from; multiset<int> to; multiset<pair<int, int> > bans; for (auto p : v) { bans.insert(p); } int ans = calc(m, from, to, bans); for (auto e : events) { if (e.first < e.second) { bans.erase(bans.find(e)); from.insert(e.first); to.insert(e.second); } else { to.erase(to.find(e.first)); from.erase(from.find(e.second)); bans.insert({e.second, e.first}); } int cand = calc(m, from, to, bans); ans = max(ans, cand); } return ans; } int main() { ios_base::sync_with_stdio(false); cout.precision(15); cout << fixed; cin.tie(0); int n, x, y; cin >> n >> x >> y; vector<pair<int, int> > xx; vector<pair<int, int> > yy; 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); xx.push_back({x1, x2}); yy.push_back({y1, y2}); } long long ansx = solve(x, xx); long long ansy = solve(y, yy); cout << ansx * ansy << endl; return 0; } |