#include <bits/stdc++.h> // Tomasz Nowak using namespace std; // XIII LO Szczecin using LL = long long; // Poland #define FOR(i, l, r) for(int i = (l); i <= (r); ++i) #define REP(i, n) FOR(i, 0, (n) - 1) mt19937_64 rng(0); int rd(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); } int inf = 0x3f3f3f3f; struct Tree { int s = 1; vector<int> val, cnt, to_add; void merge(int v) { val[v] = val[2 * v]; cnt[v] = cnt[2 * v]; if(val[v] < val[2 * v + 1]) { val[v] = val[2 * v + 1]; cnt[v] = cnt[2 * v + 1]; } else if(val[v] == val[2 * v + 1]) cnt[v] += cnt[2 * v + 1]; val[v] += to_add[v]; } Tree(vector<int> w) { int n = int(w.size()); while(s < n) s *= 2; val = cnt = to_add = vector<int>(2 * s); fill(val.begin(), val.end(), -inf); REP(i, n) val[i + s] = 0; REP(i, n) cnt[i + s] = w[i]; for(int v = s - 1; v > 0; --v) merge(v); } void add(int l, int r, int x) { l += s; r += s; val[l] += x; if(l != r) val[r] += x; while(l != 1) { if(l / 2 != r / 2) { if(~l & 1) { val[l + 1] += x; to_add[l + 1] += x; } if(r & 1) { val[r - 1] += x; to_add[r - 1] += x; } } merge(l / 2); if(l / 2 != r / 2) merge(r / 2); l /= 2; r /= 2; } } int get() { return cnt[1]; } }; int solve(int n, int X, vector<array<int, 2>> &in) { vector<int> sorted = {0, X - 1, X}; for(auto p : in) for(int x : p) { sorted.emplace_back(x); sorted.emplace_back(x + 1); } sort(sorted.begin(), sorted.end()); vector<int> nodup = {sorted[0]}; FOR(i, 1, int(sorted.size()) - 1) if(sorted[i] != sorted[i - 1]) nodup.emplace_back(sorted[i]); X = int(nodup.size()); vector<int> len(X - 1); REP(i, X - 1) len[i] = nodup[i + 1] - nodup[i]; auto scaled = [&](int x) { return int(distance(nodup.begin(), lower_bound(nodup.begin(), nodup.end(), x))); }; for(auto &p : in) for(int &x : p) x = scaled(x); Tree tree(len); vector<vector<int>> last(X); REP(i, n) { last[in[i][0]].emplace_back(i); last[in[i][1] + 1].emplace_back(i); } auto add = [&](int i, int val) { tree.add(in[i][0], in[i][1], val); }; REP(i, n) add(i, -1); int ret = 0; REP(x, X) { for(int i : last[x]) add(i, x == in[i][0] ? 2 : -2); ret = max(ret, tree.get()); } return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, X, Y; cin >> n >> X >> Y; //n = 500000; //X = Y = int(1e9); array<vector<array<int, 2>>, 2> in; REP(d, 2) in[d].resize(n); REP(i, n) { array<array<int, 2>, 2> a = {in[0][i], in[1][i]}; cin >> a[0][0] >> a[1][0] >> a[0][1] >> a[1][1]; //REP(d, 2) //REP(dd, 2) //a[d][dd] = rd(0, int(1e9) - 1); REP(d, 2) { if(a[d][0] > a[d][1]) swap(a[d][0], a[d][1]); --a[d][1]; } REP(d, 2) REP(dd, 2) in[d][i][dd] = a[d][dd]; } cout << solve(n, X, in[0]) * LL(solve(n, Y, in[1])) << '\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 | #include <bits/stdc++.h> // Tomasz Nowak using namespace std; // XIII LO Szczecin using LL = long long; // Poland #define FOR(i, l, r) for(int i = (l); i <= (r); ++i) #define REP(i, n) FOR(i, 0, (n) - 1) mt19937_64 rng(0); int rd(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); } int inf = 0x3f3f3f3f; struct Tree { int s = 1; vector<int> val, cnt, to_add; void merge(int v) { val[v] = val[2 * v]; cnt[v] = cnt[2 * v]; if(val[v] < val[2 * v + 1]) { val[v] = val[2 * v + 1]; cnt[v] = cnt[2 * v + 1]; } else if(val[v] == val[2 * v + 1]) cnt[v] += cnt[2 * v + 1]; val[v] += to_add[v]; } Tree(vector<int> w) { int n = int(w.size()); while(s < n) s *= 2; val = cnt = to_add = vector<int>(2 * s); fill(val.begin(), val.end(), -inf); REP(i, n) val[i + s] = 0; REP(i, n) cnt[i + s] = w[i]; for(int v = s - 1; v > 0; --v) merge(v); } void add(int l, int r, int x) { l += s; r += s; val[l] += x; if(l != r) val[r] += x; while(l != 1) { if(l / 2 != r / 2) { if(~l & 1) { val[l + 1] += x; to_add[l + 1] += x; } if(r & 1) { val[r - 1] += x; to_add[r - 1] += x; } } merge(l / 2); if(l / 2 != r / 2) merge(r / 2); l /= 2; r /= 2; } } int get() { return cnt[1]; } }; int solve(int n, int X, vector<array<int, 2>> &in) { vector<int> sorted = {0, X - 1, X}; for(auto p : in) for(int x : p) { sorted.emplace_back(x); sorted.emplace_back(x + 1); } sort(sorted.begin(), sorted.end()); vector<int> nodup = {sorted[0]}; FOR(i, 1, int(sorted.size()) - 1) if(sorted[i] != sorted[i - 1]) nodup.emplace_back(sorted[i]); X = int(nodup.size()); vector<int> len(X - 1); REP(i, X - 1) len[i] = nodup[i + 1] - nodup[i]; auto scaled = [&](int x) { return int(distance(nodup.begin(), lower_bound(nodup.begin(), nodup.end(), x))); }; for(auto &p : in) for(int &x : p) x = scaled(x); Tree tree(len); vector<vector<int>> last(X); REP(i, n) { last[in[i][0]].emplace_back(i); last[in[i][1] + 1].emplace_back(i); } auto add = [&](int i, int val) { tree.add(in[i][0], in[i][1], val); }; REP(i, n) add(i, -1); int ret = 0; REP(x, X) { for(int i : last[x]) add(i, x == in[i][0] ? 2 : -2); ret = max(ret, tree.get()); } return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, X, Y; cin >> n >> X >> Y; //n = 500000; //X = Y = int(1e9); array<vector<array<int, 2>>, 2> in; REP(d, 2) in[d].resize(n); REP(i, n) { array<array<int, 2>, 2> a = {in[0][i], in[1][i]}; cin >> a[0][0] >> a[1][0] >> a[0][1] >> a[1][1]; //REP(d, 2) //REP(dd, 2) //a[d][dd] = rd(0, int(1e9) - 1); REP(d, 2) { if(a[d][0] > a[d][1]) swap(a[d][0], a[d][1]); --a[d][1]; } REP(d, 2) REP(dd, 2) in[d][i][dd] = a[d][dd]; } cout << solve(n, X, in[0]) * LL(solve(n, Y, in[1])) << '\n'; } |