#include <bits/stdc++.h> using namespace std; #define PII pair<int, int> #define VI vector<int> #define VPII vector<PII> #define LL long long #define LD long double #define f first #define s second #define MP make_pair #define PB push_back #define endl '\n' #define ALL(c) (c).begin(), (c).end() #define SIZ(c) (int)(c).size() #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, b, e) for (int i = (b); i <= (int)(e); i++) #define FORD(i, b, e) for (int i = (b); i >= (int)(e); i--) #define ll long long #define st f #define nd s #define pb PB #define eb emplace_back #define mp make_pair #define siz(c) SIZ(c) const int inf = 1e9 + 7; const LL INF = 1e18L + 7; #define sim template<class n sim, class s> ostream & operator << (ostream &p, pair<n, s> x) {return p << "<" << x.f << ", " << x.s << ">";} sim> auto operator << (ostream &p, n y) -> typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type {int o = 0; p << "{"; for (auto c : y) {if (o++) p << ", "; p << c;} return p << "}";} void dor() {cerr << endl;} sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);} sim, class s> void mini(n &p, s y) {if (p > y) p = y;} sim, class s> void maxi(n &p, s y) {if (p < y) p = y;} #ifdef DEB #define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__) #else #define debug(...) #endif #define I(x) #x " = ", (x), " " #define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " " #ifndef LOCAL #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #else #include</Users/dawid/algo/mac/ordered_set> #endif #define int ll #define y1 slmqmsqslqmsq const int N = 1<<20; int n, X, Y; int x1[N]; int x2[N]; int y1[N]; int y2[N]; int l[N]; int r[N]; int load[2*N]; int Min[2*N]; int cnt[2*N]; VI zaczyna[N]; VI konczy[N]; VI val; void merge(int v) { if(Min[2*v]==Min[2*v+1]) { Min[v] = Min[2*v]; cnt[v] = cnt[2*v] + cnt[2*v+1]; } else if(Min[2*v]<Min[2*v+1]) { Min[v] = Min[2*v]; cnt[v] = cnt[2*v]; } else { Min[v] = Min[2*v+1]; cnt[v] = cnt[2*v+1]; } Min[v] += load[v]; } void insert(int a, int b, int c, int v = 1, int l = 0, int r = N-1) { if(a>r || l>b) return; if(a<=l && r<=b) { load[v] += c; Min[v] += c; return; } insert(a, b, c, 2*v, l, (l+r)/2); insert(a, b, c, 2*v+1, (l+r)/2+1, r); merge(v); } void clear() { memset(Min, 0, sizeof Min); memset(load, 0, sizeof load); memset(cnt, 0, sizeof cnt); val.clear(); for(int i = 0; i < N; ++i) { zaczyna[i].clear(); konczy[i].clear(); } } int solve(int M) { for(int i = 1; i <= n; ++i) { val.pb(l[i]); val.pb(r[i]); } val.pb(M); val.pb(0); sort(ALL(val)); val.erase(unique(ALL(val)), val.end()); for(int i = 0; i+1 < siz(val); ++i) { cnt[i+N] = val[i+1] - val[i]; } for(int i = siz(val)-1; i < N; ++i) { cnt[i] = 1; Min[i] = inf; } for(int i = N-1; i >= 1; --i) { merge(i); } //debug(val); for(int i = 1; i <= n; ++i) { l[i] = lower_bound(ALL(val), l[i]) - val.begin(); r[i] = lower_bound(ALL(val), r[i]) - val.begin(); insert(l[i], r[i]-1, 1); //debug(l[i], r[i]); zaczyna[l[i]].pb(i); konczy[r[i]].pb(i); } int ans = 0; for(int i = 0; i+1 < siz(val); ++i) { for(auto it:zaczyna[i]) { insert(l[it], r[it]-1, -1); insert(0, l[it]-1, 1); insert(r[it], siz(val)-2, 1); } for(auto it:konczy[i]) { insert(l[it], r[it]-1, 1); insert(0, l[it]-1, -1); insert(r[it], siz(val)-2, -1); } if(Min[1]==0) ans = max(ans, cnt[1]); } clear(); return ans; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> n >> X >> Y; for(int i = 1; i <= n; ++i) { cin >> x1[i] >> y1[i] >> x2[i] >> y2[i]; if(x1[i] > x2[i]) swap(x1[i], x2[i]); if(y1[i] > y2[i]) swap(y1[i], y2[i]); l[i] = x1[i]; r[i] = x2[i]; } int ans_x = solve(X); //debug(ans_x); for(int i = 1; i <= n; ++i) { l[i] = y1[i]; r[i] = y2[i]; } int ans_y = solve(Y); cout << ans_x * ans_y << endl; }
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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | #include <bits/stdc++.h> using namespace std; #define PII pair<int, int> #define VI vector<int> #define VPII vector<PII> #define LL long long #define LD long double #define f first #define s second #define MP make_pair #define PB push_back #define endl '\n' #define ALL(c) (c).begin(), (c).end() #define SIZ(c) (int)(c).size() #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, b, e) for (int i = (b); i <= (int)(e); i++) #define FORD(i, b, e) for (int i = (b); i >= (int)(e); i--) #define ll long long #define st f #define nd s #define pb PB #define eb emplace_back #define mp make_pair #define siz(c) SIZ(c) const int inf = 1e9 + 7; const LL INF = 1e18L + 7; #define sim template<class n sim, class s> ostream & operator << (ostream &p, pair<n, s> x) {return p << "<" << x.f << ", " << x.s << ">";} sim> auto operator << (ostream &p, n y) -> typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type {int o = 0; p << "{"; for (auto c : y) {if (o++) p << ", "; p << c;} return p << "}";} void dor() {cerr << endl;} sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);} sim, class s> void mini(n &p, s y) {if (p > y) p = y;} sim, class s> void maxi(n &p, s y) {if (p < y) p = y;} #ifdef DEB #define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__) #else #define debug(...) #endif #define I(x) #x " = ", (x), " " #define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " " #ifndef LOCAL #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #else #include</Users/dawid/algo/mac/ordered_set> #endif #define int ll #define y1 slmqmsqslqmsq const int N = 1<<20; int n, X, Y; int x1[N]; int x2[N]; int y1[N]; int y2[N]; int l[N]; int r[N]; int load[2*N]; int Min[2*N]; int cnt[2*N]; VI zaczyna[N]; VI konczy[N]; VI val; void merge(int v) { if(Min[2*v]==Min[2*v+1]) { Min[v] = Min[2*v]; cnt[v] = cnt[2*v] + cnt[2*v+1]; } else if(Min[2*v]<Min[2*v+1]) { Min[v] = Min[2*v]; cnt[v] = cnt[2*v]; } else { Min[v] = Min[2*v+1]; cnt[v] = cnt[2*v+1]; } Min[v] += load[v]; } void insert(int a, int b, int c, int v = 1, int l = 0, int r = N-1) { if(a>r || l>b) return; if(a<=l && r<=b) { load[v] += c; Min[v] += c; return; } insert(a, b, c, 2*v, l, (l+r)/2); insert(a, b, c, 2*v+1, (l+r)/2+1, r); merge(v); } void clear() { memset(Min, 0, sizeof Min); memset(load, 0, sizeof load); memset(cnt, 0, sizeof cnt); val.clear(); for(int i = 0; i < N; ++i) { zaczyna[i].clear(); konczy[i].clear(); } } int solve(int M) { for(int i = 1; i <= n; ++i) { val.pb(l[i]); val.pb(r[i]); } val.pb(M); val.pb(0); sort(ALL(val)); val.erase(unique(ALL(val)), val.end()); for(int i = 0; i+1 < siz(val); ++i) { cnt[i+N] = val[i+1] - val[i]; } for(int i = siz(val)-1; i < N; ++i) { cnt[i] = 1; Min[i] = inf; } for(int i = N-1; i >= 1; --i) { merge(i); } //debug(val); for(int i = 1; i <= n; ++i) { l[i] = lower_bound(ALL(val), l[i]) - val.begin(); r[i] = lower_bound(ALL(val), r[i]) - val.begin(); insert(l[i], r[i]-1, 1); //debug(l[i], r[i]); zaczyna[l[i]].pb(i); konczy[r[i]].pb(i); } int ans = 0; for(int i = 0; i+1 < siz(val); ++i) { for(auto it:zaczyna[i]) { insert(l[it], r[it]-1, -1); insert(0, l[it]-1, 1); insert(r[it], siz(val)-2, 1); } for(auto it:konczy[i]) { insert(l[it], r[it]-1, 1); insert(0, l[it]-1, -1); insert(r[it], siz(val)-2, -1); } if(Min[1]==0) ans = max(ans, cnt[1]); } clear(); return ans; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> n >> X >> Y; for(int i = 1; i <= n; ++i) { cin >> x1[i] >> y1[i] >> x2[i] >> y2[i]; if(x1[i] > x2[i]) swap(x1[i], x2[i]); if(y1[i] > y2[i]) swap(y1[i], y2[i]); l[i] = x1[i]; r[i] = x2[i]; } int ans_x = solve(X); //debug(ans_x); for(int i = 1; i <= n; ++i) { l[i] = y1[i]; r[i] = y2[i]; } int ans_y = solve(Y); cout << ans_x * ans_y << endl; } |