#include <iostream> #include <bitset> #include <vector> #include <algorithm> #include <cmath> using namespace std; int count(const vector<int> &v) { int r = 0; for (auto i = v.begin(); i != v.end(); i += 2) { r += *(i + 1) - *i; } return r; } void intersect(const vector<int> &v, int b, int e, vector<vector<int>> &axis) { bool on = true; bool in = false; bool wasIn = false; vector<int> a, aPrim; for (const int &i : v) { on = !on; if (!(b < i && !wasIn) && !(i > e && in)) { if (in) a.push_back(i); else aPrim.push_back(i); } if (b < i && !wasIn) { in = true; wasIn = true; //cout << "begin at: " << i << endl; if (on) { a.push_back(b); aPrim.push_back(b); } if (i <= e) a.push_back(i); } if (i > e && in) { in = false; //cout << "end at: " << i << endl; if (on) { a.push_back(e); aPrim.push_back(e); } aPrim.push_back(i); } } /*cout << "a: "; for (const int &i : a) cout << i << " "; cout << endl; cout << "aPrim: "; for (const int &i : aPrim) cout << i << " "; cout << endl;*/ axis.push_back(a); axis.push_back(aPrim); /*if (count(a) >= count(aPrim)) return axis.push_back(a); else return axis.push_back(aPrim);*/ } int main() { ios_base::sync_with_stdio(false); int n, X, Y, x1, y1, x2, y2; cin >> n >> X >> Y; vector<vector<int>> xs = {{0, X}}, ys = {{0, Y}}; vector<vector<int>> newx, newy; while (n--) { newx.clear(); newy.clear(); cin >> x1 >> y1 >> x2 >> y2; for (const auto &x : xs) { intersect(x, min(x1, x2), max(x1, x2), newx); } //xs = newx; swap(xs, newx); for (const auto &y : ys) { intersect(y, min(y1, y2), max(y1, y2), newy); } //ys = newy; swap(ys, newy); } int maxx = 0, maxy = 0; for (const auto &x : xs) { maxx = max(count(x), maxx); } for (const auto &y : ys) { maxy = max(count(y), maxy); } cout << maxx * maxy; }
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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | #include <iostream> #include <bitset> #include <vector> #include <algorithm> #include <cmath> using namespace std; int count(const vector<int> &v) { int r = 0; for (auto i = v.begin(); i != v.end(); i += 2) { r += *(i + 1) - *i; } return r; } void intersect(const vector<int> &v, int b, int e, vector<vector<int>> &axis) { bool on = true; bool in = false; bool wasIn = false; vector<int> a, aPrim; for (const int &i : v) { on = !on; if (!(b < i && !wasIn) && !(i > e && in)) { if (in) a.push_back(i); else aPrim.push_back(i); } if (b < i && !wasIn) { in = true; wasIn = true; //cout << "begin at: " << i << endl; if (on) { a.push_back(b); aPrim.push_back(b); } if (i <= e) a.push_back(i); } if (i > e && in) { in = false; //cout << "end at: " << i << endl; if (on) { a.push_back(e); aPrim.push_back(e); } aPrim.push_back(i); } } /*cout << "a: "; for (const int &i : a) cout << i << " "; cout << endl; cout << "aPrim: "; for (const int &i : aPrim) cout << i << " "; cout << endl;*/ axis.push_back(a); axis.push_back(aPrim); /*if (count(a) >= count(aPrim)) return axis.push_back(a); else return axis.push_back(aPrim);*/ } int main() { ios_base::sync_with_stdio(false); int n, X, Y, x1, y1, x2, y2; cin >> n >> X >> Y; vector<vector<int>> xs = {{0, X}}, ys = {{0, Y}}; vector<vector<int>> newx, newy; while (n--) { newx.clear(); newy.clear(); cin >> x1 >> y1 >> x2 >> y2; for (const auto &x : xs) { intersect(x, min(x1, x2), max(x1, x2), newx); } //xs = newx; swap(xs, newx); for (const auto &y : ys) { intersect(y, min(y1, y2), max(y1, y2), newy); } //ys = newy; swap(ys, newy); } int maxx = 0, maxy = 0; for (const auto &x : xs) { maxx = max(count(x), maxx); } for (const auto &y : ys) { maxy = max(count(y), maxy); } cout << maxx * maxy; } |