#include<bits/stdc++.h> using namespace std; ostream& operator<<(ostream &out, string str) { for(char c : str) out << c; return out; } template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) { return out << "(" << p.first << ", " << p.second << ")"; } template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) { out << "{"; for(auto it = a.begin(); it != a.end(); it = next(it)) out << (it != a.begin() ? ", " : "") << *it; return out << "}"; } void dump() { cerr << "\n"; } template<class T, class... Ts> void dump(T a, Ts... x) { cerr << a << ", "; dump(x...); } #ifdef DEBUG # define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__) #else # define debug(...) false #endif #define REP(i, n) for(int i = 0; i < n; i++) #define FOR(i, a, b) for(int i = a; i <= b; i++) #define ST first #define ND second template<class T> int size(T && a) { return a.size(); } using LL = long long; using PII = pair<int, int>; mt19937 _gen(2137); int rd(int a, int b) { return uniform_int_distribution<int>(a, b)(_gen); } struct Node { int size = 1, val = 0; int cnt = 0, lazy = 0; }; struct Tree { vector<Node> tree; int size = 1; Tree(int n, vector<int> w) { while(size < n) size *= 2; tree.resize(size * 2); for(int i = size; i < size + n; i++) tree[i].cnt = w[i - size]; for(int i = size + n; i < size * 2; i++) tree[i].val = -1e7; for(int i = size - 1; i >= 1; i--) { tree[i].size = tree[i * 2].size + tree[i * 2 + 1].size; tree[i].cnt = tree[i * 2].cnt + tree[i * 2 + 1].cnt; } } inline void propagate(int v) { if(tree[v].lazy == 0) return; REP(i, 2) { tree[v * 2 + i].val += tree[v].lazy; tree[v * 2 + i].lazy += tree[v].lazy; } tree[v].lazy = 0; } int query() { return tree[1].cnt; } inline void add(int l, int r, int val, int v = 1) { if(l == 0 && r == tree[v].size - 1) { tree[v].val += val; tree[v].lazy += val; return; } propagate(v); int m = tree[v].size / 2; if(r < m) add(l, r, val, v * 2); else if(m <= l) add(l - m, r - m, val, v * 2 + 1); else add(l, m - 1, val, v * 2), add(0, r - m, val, v * 2 + 1); tree[v].val = max(tree[v * 2].val, tree[v * 2 + 1].val); tree[v].cnt = 0; REP(i, 2) if(tree[v].val == tree[v * 2 + i].val) tree[v].cnt += tree[v * 2 + i].cnt; } }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, X, Y; cin >> n >> X >> Y; vector<PII> x(n), y(n); REP(i, n) cin >> x[i].ST >> y[i].ST >> x[i].ND >> y[i].ND; auto solve = [n](int m, vector<PII> &x) -> LL { vector<int> q = {0, m}; REP(i, n) { if(x[i].ST > x[i].ND) swap(x[i].ST, x[i].ND); q.emplace_back(x[i].ST); q.emplace_back(x[i].ND); } sort(q.begin(), q.end()); auto u = unique(q.begin(), q.end()); q.erase(u, q.end()); vector<int> w(size(q) - 1); REP(i, size(w)) w[i] = q[i + 1] - q[i]; Tree tree(size(w), w); auto scale = [&](int &val) { auto it = lower_bound(q.begin(), q.end(), val); val = distance(q.begin(), it); }; REP(i, n) scale(x[i].ST), scale(x[i].ND); vector<vector<int>> evs(size(q)); REP(i, n) { tree.add(x[i].ST, x[i].ND - 1, -1); evs[x[i].ST].emplace_back(i); evs[x[i].ND].emplace_back(i); } int ans = 0; vector<int> on(n, 1); for(auto &v : evs) { for(int &i : v) { tree.add(x[i].ST, x[i].ND - 1, 2 * on[i]); on[i] *= -1; } ans = max(ans, tree.query()); } return ans; }; cout << solve(X, x) * solve(Y, y) << "\n"; }
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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | #include<bits/stdc++.h> using namespace std; ostream& operator<<(ostream &out, string str) { for(char c : str) out << c; return out; } template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) { return out << "(" << p.first << ", " << p.second << ")"; } template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) { out << "{"; for(auto it = a.begin(); it != a.end(); it = next(it)) out << (it != a.begin() ? ", " : "") << *it; return out << "}"; } void dump() { cerr << "\n"; } template<class T, class... Ts> void dump(T a, Ts... x) { cerr << a << ", "; dump(x...); } #ifdef DEBUG # define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__) #else # define debug(...) false #endif #define REP(i, n) for(int i = 0; i < n; i++) #define FOR(i, a, b) for(int i = a; i <= b; i++) #define ST first #define ND second template<class T> int size(T && a) { return a.size(); } using LL = long long; using PII = pair<int, int>; mt19937 _gen(2137); int rd(int a, int b) { return uniform_int_distribution<int>(a, b)(_gen); } struct Node { int size = 1, val = 0; int cnt = 0, lazy = 0; }; struct Tree { vector<Node> tree; int size = 1; Tree(int n, vector<int> w) { while(size < n) size *= 2; tree.resize(size * 2); for(int i = size; i < size + n; i++) tree[i].cnt = w[i - size]; for(int i = size + n; i < size * 2; i++) tree[i].val = -1e7; for(int i = size - 1; i >= 1; i--) { tree[i].size = tree[i * 2].size + tree[i * 2 + 1].size; tree[i].cnt = tree[i * 2].cnt + tree[i * 2 + 1].cnt; } } inline void propagate(int v) { if(tree[v].lazy == 0) return; REP(i, 2) { tree[v * 2 + i].val += tree[v].lazy; tree[v * 2 + i].lazy += tree[v].lazy; } tree[v].lazy = 0; } int query() { return tree[1].cnt; } inline void add(int l, int r, int val, int v = 1) { if(l == 0 && r == tree[v].size - 1) { tree[v].val += val; tree[v].lazy += val; return; } propagate(v); int m = tree[v].size / 2; if(r < m) add(l, r, val, v * 2); else if(m <= l) add(l - m, r - m, val, v * 2 + 1); else add(l, m - 1, val, v * 2), add(0, r - m, val, v * 2 + 1); tree[v].val = max(tree[v * 2].val, tree[v * 2 + 1].val); tree[v].cnt = 0; REP(i, 2) if(tree[v].val == tree[v * 2 + i].val) tree[v].cnt += tree[v * 2 + i].cnt; } }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, X, Y; cin >> n >> X >> Y; vector<PII> x(n), y(n); REP(i, n) cin >> x[i].ST >> y[i].ST >> x[i].ND >> y[i].ND; auto solve = [n](int m, vector<PII> &x) -> LL { vector<int> q = {0, m}; REP(i, n) { if(x[i].ST > x[i].ND) swap(x[i].ST, x[i].ND); q.emplace_back(x[i].ST); q.emplace_back(x[i].ND); } sort(q.begin(), q.end()); auto u = unique(q.begin(), q.end()); q.erase(u, q.end()); vector<int> w(size(q) - 1); REP(i, size(w)) w[i] = q[i + 1] - q[i]; Tree tree(size(w), w); auto scale = [&](int &val) { auto it = lower_bound(q.begin(), q.end(), val); val = distance(q.begin(), it); }; REP(i, n) scale(x[i].ST), scale(x[i].ND); vector<vector<int>> evs(size(q)); REP(i, n) { tree.add(x[i].ST, x[i].ND - 1, -1); evs[x[i].ST].emplace_back(i); evs[x[i].ND].emplace_back(i); } int ans = 0; vector<int> on(n, 1); for(auto &v : evs) { for(int &i : v) { tree.add(x[i].ST, x[i].ND - 1, 2 * on[i]); on[i] *= -1; } ans = max(ans, tree.query()); } return ans; }; cout << solve(X, x) * solve(Y, y) << "\n"; } |