//#pragma GCC optimize("Ofast") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma warning(disable:4786) #pragma warning(disable:4996) #include <ctime> #include<list> #include <numeric> #include<bitset> #include<iostream> #include<cstdio> #include<algorithm> #include<vector> #include<set> #include<map> #include<functional> #include<string> #include<cstring> #include<cstdlib> #include<queue> #include<utility> #include<fstream> #include<sstream> #include<cmath> #include<stack> #include<assert.h> #include<unordered_map> #include<unordered_set> #include <array> using namespace std; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } template<class c> typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) { cerr << boolalpha << i; return *this; } template<class c, int = 0> typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) { return *this << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define watch(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define MEM(a, b) memset(a, (b), sizeof(a)) #define CLR(a) memset(a, 0, sizeof(a)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) ) #define S(X) ( (X) * (X) ) #define SZ(V) (int )V.size() #define FORN(i, n) for(int i = 0; i < n; i++) #define FORAB(i, a, b) for(int i = a; i <= b; i++) #define ALL(V) V.begin(), V.end() #define IN(A, B, C) ((B) <= (A) && (A) <= (C)) #define AIN(A, B, C) assert(IN(A, B, C)) //typedef int LL; typedef long long int LL; //typedef __int128 LLL; typedef long long LLL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef pair<double, double> PDD; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<PLL > VPL; typedef vector<PII > VP; typedef vector<double> VD; typedef vector<vector<int>> VVI; typedef vector<string> VS; typedef long double ld; #define MAXN 200005 const LL MOD = 998244353; //const LL MOD = 998244353; const LL INF = 2000000000000000001LL; int n; LL X, Y; VP VX, VY; struct Side { int at, mode, id; }; bool operator<(Side A, Side B) { return A.at < B.at; } struct Data { int maxm, cnt, lazy; int l, r; }; struct Tree { VI V; vector<Data> D; void build(int at, int l, int r) { if (l == r) { D[at] = { 0, V[r + 1] - V[l], 0, V[l], V[r + 1] - 1 }; return; } int m = (l + r) / 2; build(at * 2, l, m); build(at * 2 + 1, m + 1, r); D[at].maxm = 0; D[at].lazy = 0; D[at].cnt = V[r + 1] - V[l]; D[at].l = D[at * 2].l; D[at].r = D[at * 2 + 1].r; } void Update(int at, int l, int r, int L, int R, int v) { if (L <= D[at].l && D[at].r <= R) { D[at].lazy += v; D[at].maxm += v; return; } if (R < D[at].l || D[at].r < L) return; if (D[at].lazy) { D[at * 2].lazy += D[at].lazy; D[at * 2 + 1].lazy += D[at].lazy; D[at * 2].maxm += D[at].lazy; D[at * 2 + 1].maxm += D[at].lazy; D[at].lazy = 0; } int m = (l + r) / 2; Update(at * 2, l, m, L, R, v); Update(at * 2 + 1, m + 1, r, L, R, v); D[at].maxm = MAX(D[at * 2].maxm, D[at * 2 + 1].maxm); D[at].lazy = 0; D[at].cnt = (D[at * 2].maxm == D[at].maxm ? D[at * 2].cnt : 0) + (D[at * 2 + 1].maxm == D[at].maxm ? D[at * 2 + 1].cnt : 0); } void init(VI& W) { V = W; D.resize(4 * SZ(V) + 1); build(1, 0, SZ(V) - 2); } int query(int n) { if (D[1].maxm == n) return D[1].cnt; return 0; } } T; LL solve(int X, VP& V) { set<int> S = { 0, X }; VP Starting, Ending; for (int i = 0; i < SZ(V); i++) { if (V[i].first) S.insert(V[i].first - 1); S.insert(V[i].first); if (V[i].second) S.insert(V[i].second - 1); S.insert(V[i].second); Starting.push_back({ V[i].first, i }); Ending.push_back({ V[i].second, i }); } sort(ALL(Starting)); sort(ALL(Ending)); VI Z; for (int s : S) Z.push_back(s); T.init(Z); for (int i = 0; i < SZ(V); i++) { if (V[i].first) T.Update(1, 0, SZ(Z) - 2, 0, V[i].first - 1, 1); T.Update(1, 0, SZ(Z) - 2, V[i].second, X - 1, 1); } int n = SZ(V); int ret = T.query(n); int s = SZ(Starting) - 1, e = SZ(Ending) - 1; for (int i = SZ(Z) - 3; i >= 0; i--) { int at = Z[i]; // jader starting > at, while (s >= 0 && Starting[s].first > at) { int id = Starting[s].second; s--; T.Update(1, 0, SZ(Z) - 2, V[id].first, V[id].second - 1, -1); if (V[id].first) T.Update(1, 0, SZ(Z) - 2, 0, V[id].first - 1, 1); T.Update(1, 0, SZ(Z) - 2, V[id].second, X - 1, 1); } // jader ending > at, while (e >= 0 && Ending[e].first > at) { int id = Ending[e].second; e--; T.Update(1, 0, SZ(Z) - 2, V[id].first, V[id].second - 1, +1); if (V[id].first) T.Update(1, 0, SZ(Z) - 2, 0, V[id].first - 1, -1); T.Update(1, 0, SZ(Z) - 2, V[id].second, X - 1, -1); } int now = T.query(n); ret = MAX(ret, now); } return ret; } void solve(int ks) { scanf("%d %lld %lld", &n, &X, &Y); VX.clear(); VY.clear(); FORN(i, n) { int x1, y1, x2, y2; scanf("%d %d %d %d", &x1, &y1, &x2, &y2); if (x1 > x2) swap(x1, x2); if (y1 > y2) swap(y1, y2); VX.push_back({ x1, x2 }); VY.push_back({ y1, y2 }); } LL a = solve(X, VX); LL b = solve(Y, VY); //printf("%lld %lld %lld\n", a, b, a * b); printf("%lld\n", a * b); } int main() { // double start_time = clock(); #ifdef LOCAL freopen("C:\\Home\\ContestCodes\\sample.in", "r", stdin); // freopen("out.out", "w", stdout); #endif if (0) { int T; scanf("%d", &T); //AIN(T, 1, 10); for (int ks = 1; ks <= T; ks++) { solve(ks); //fprintf(stderr, "%d done\n", ks); } } else { solve(0); } // double end_time = clock(); // fprintf(stderr, "Time = %lf\n", (end_time - start_time) / CLOCKS_PER_SEC); 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 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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | //#pragma GCC optimize("Ofast") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma warning(disable:4786) #pragma warning(disable:4996) #include <ctime> #include<list> #include <numeric> #include<bitset> #include<iostream> #include<cstdio> #include<algorithm> #include<vector> #include<set> #include<map> #include<functional> #include<string> #include<cstring> #include<cstdlib> #include<queue> #include<utility> #include<fstream> #include<sstream> #include<cmath> #include<stack> #include<assert.h> #include<unordered_map> #include<unordered_set> #include <array> using namespace std; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } template<class c> typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) { cerr << boolalpha << i; return *this; } template<class c, int = 0> typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) { return *this << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define watch(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define MEM(a, b) memset(a, (b), sizeof(a)) #define CLR(a) memset(a, 0, sizeof(a)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) ) #define S(X) ( (X) * (X) ) #define SZ(V) (int )V.size() #define FORN(i, n) for(int i = 0; i < n; i++) #define FORAB(i, a, b) for(int i = a; i <= b; i++) #define ALL(V) V.begin(), V.end() #define IN(A, B, C) ((B) <= (A) && (A) <= (C)) #define AIN(A, B, C) assert(IN(A, B, C)) //typedef int LL; typedef long long int LL; //typedef __int128 LLL; typedef long long LLL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef pair<double, double> PDD; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<PLL > VPL; typedef vector<PII > VP; typedef vector<double> VD; typedef vector<vector<int>> VVI; typedef vector<string> VS; typedef long double ld; #define MAXN 200005 const LL MOD = 998244353; //const LL MOD = 998244353; const LL INF = 2000000000000000001LL; int n; LL X, Y; VP VX, VY; struct Side { int at, mode, id; }; bool operator<(Side A, Side B) { return A.at < B.at; } struct Data { int maxm, cnt, lazy; int l, r; }; struct Tree { VI V; vector<Data> D; void build(int at, int l, int r) { if (l == r) { D[at] = { 0, V[r + 1] - V[l], 0, V[l], V[r + 1] - 1 }; return; } int m = (l + r) / 2; build(at * 2, l, m); build(at * 2 + 1, m + 1, r); D[at].maxm = 0; D[at].lazy = 0; D[at].cnt = V[r + 1] - V[l]; D[at].l = D[at * 2].l; D[at].r = D[at * 2 + 1].r; } void Update(int at, int l, int r, int L, int R, int v) { if (L <= D[at].l && D[at].r <= R) { D[at].lazy += v; D[at].maxm += v; return; } if (R < D[at].l || D[at].r < L) return; if (D[at].lazy) { D[at * 2].lazy += D[at].lazy; D[at * 2 + 1].lazy += D[at].lazy; D[at * 2].maxm += D[at].lazy; D[at * 2 + 1].maxm += D[at].lazy; D[at].lazy = 0; } int m = (l + r) / 2; Update(at * 2, l, m, L, R, v); Update(at * 2 + 1, m + 1, r, L, R, v); D[at].maxm = MAX(D[at * 2].maxm, D[at * 2 + 1].maxm); D[at].lazy = 0; D[at].cnt = (D[at * 2].maxm == D[at].maxm ? D[at * 2].cnt : 0) + (D[at * 2 + 1].maxm == D[at].maxm ? D[at * 2 + 1].cnt : 0); } void init(VI& W) { V = W; D.resize(4 * SZ(V) + 1); build(1, 0, SZ(V) - 2); } int query(int n) { if (D[1].maxm == n) return D[1].cnt; return 0; } } T; LL solve(int X, VP& V) { set<int> S = { 0, X }; VP Starting, Ending; for (int i = 0; i < SZ(V); i++) { if (V[i].first) S.insert(V[i].first - 1); S.insert(V[i].first); if (V[i].second) S.insert(V[i].second - 1); S.insert(V[i].second); Starting.push_back({ V[i].first, i }); Ending.push_back({ V[i].second, i }); } sort(ALL(Starting)); sort(ALL(Ending)); VI Z; for (int s : S) Z.push_back(s); T.init(Z); for (int i = 0; i < SZ(V); i++) { if (V[i].first) T.Update(1, 0, SZ(Z) - 2, 0, V[i].first - 1, 1); T.Update(1, 0, SZ(Z) - 2, V[i].second, X - 1, 1); } int n = SZ(V); int ret = T.query(n); int s = SZ(Starting) - 1, e = SZ(Ending) - 1; for (int i = SZ(Z) - 3; i >= 0; i--) { int at = Z[i]; // jader starting > at, while (s >= 0 && Starting[s].first > at) { int id = Starting[s].second; s--; T.Update(1, 0, SZ(Z) - 2, V[id].first, V[id].second - 1, -1); if (V[id].first) T.Update(1, 0, SZ(Z) - 2, 0, V[id].first - 1, 1); T.Update(1, 0, SZ(Z) - 2, V[id].second, X - 1, 1); } // jader ending > at, while (e >= 0 && Ending[e].first > at) { int id = Ending[e].second; e--; T.Update(1, 0, SZ(Z) - 2, V[id].first, V[id].second - 1, +1); if (V[id].first) T.Update(1, 0, SZ(Z) - 2, 0, V[id].first - 1, -1); T.Update(1, 0, SZ(Z) - 2, V[id].second, X - 1, -1); } int now = T.query(n); ret = MAX(ret, now); } return ret; } void solve(int ks) { scanf("%d %lld %lld", &n, &X, &Y); VX.clear(); VY.clear(); FORN(i, n) { int x1, y1, x2, y2; scanf("%d %d %d %d", &x1, &y1, &x2, &y2); if (x1 > x2) swap(x1, x2); if (y1 > y2) swap(y1, y2); VX.push_back({ x1, x2 }); VY.push_back({ y1, y2 }); } LL a = solve(X, VX); LL b = solve(Y, VY); //printf("%lld %lld %lld\n", a, b, a * b); printf("%lld\n", a * b); } int main() { // double start_time = clock(); #ifdef LOCAL freopen("C:\\Home\\ContestCodes\\sample.in", "r", stdin); // freopen("out.out", "w", stdout); #endif if (0) { int T; scanf("%d", &T); //AIN(T, 1, 10); for (int ks = 1; ks <= T; ks++) { solve(ks); //fprintf(stderr, "%d done\n", ks); } } else { solve(0); } // double end_time = clock(); // fprintf(stderr, "Time = %lf\n", (end_time - start_time) / CLOCKS_PER_SEC); return 0; } |