#include <bits/stdc++.h> using namespace std; #define PII pair<int, int> #define PLL pair<LL, LL> #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 pb pop_back #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 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], " " const int M = 1024 * 1024; struct node { int mx, add, ile; }; int n, S[M]; PII T[M]; VPII Z; unordered_map<int, int> mapa; node D[2 * M]; int pp, kk, xx; inline void pchaj(int v) { D[2 * v].add += D[v].add; D[2 * v + 1].add += D[v].add; D[v].add = 0; } inline void popraw(int v) { int l = D[2 * v].mx + D[2 * v].add; int r = D[2 * v + 1].mx + D[2 * v + 1].add; D[v].mx = max(l, r); D[v].ile = 0; if (l == D[v].mx) { D[v].ile += D[2 * v].ile; } if (r == D[v].mx) { D[v].ile += D[2 * v + 1].ile; } } inline void add(int v, int vp, int vk) { if (pp > kk || vp > kk || vk < pp) { return; } if (vp >= pp && vk <= kk) { D[v].add += xx; return; } pchaj(v); int mid = (vp + vk) / 2; add(2 * v, vp, mid); add(2 * v + 1, mid + 1, vk); popraw(v); } int solve(VPII V, int m) { Z.clear(); mapa.clear(); FOR(i, 0, 2 * M - 1) { D[i] = node{0, 0, 0}; } VI X; FOR(i, 0, n - 1) { T[i + 1] = V[i]; Z.PB(MP(V[i].f, i + 1)); Z.PB(MP(V[i].s, -i - 1)); X.PB(V[i].f); X.PB(V[i].s); } X.PB(0); X.PB(m); sort(ALL(Z)); sort(ALL(X)); int prv = 0, tmp = 0; for (auto x : X) { if (x != prv) { S[tmp] = x - prv; prv = x; tmp++; mapa[prv] = tmp; } } FOR(i, 0, tmp - 1) { D[i + M].ile = S[i]; } FORD(i, M - 1, 0) { D[i].ile = D[2 * i].ile + D[2 * i + 1].ile; } for (auto& x : Z) { x.f = mapa[x.f]; if (x.s > 0) { T[x.s].f = x.f; } else { T[-x.s].s = x.f; } } //return 0; FOR(i, 1, n) { D[1].add++; pp = T[i].f; kk = T[i].s - 1; xx = -1; add(1, 0, M - 1); } int res = 0; if (D[1].mx + D[1].add == n) { maxi(res, D[1].ile); } for (auto x : Z) { if (x.s > 0) { D[1].add--; pp = T[x.s].f; kk = T[x.s].s - 1; xx = 2; add(1, 0, M - 1); } else { D[1].add++; pp = T[-x.s].f; kk = T[-x.s].s - 1; xx = -2; add(1, 0, M - 1); } if (D[1].mx + D[1].add == n) { maxi(res, D[1].ile); } } return res; } int32_t main() { //ios_base::sync_with_stdio(0); //cin.tie(NULL); int x, y; scanf("%d%d%d", &n, &x, &y); //n = 5e5; //x = 1e9; //y = 1e9; VPII V[2]; FOR(i, 1, n) { int x1, x2, y1, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2); /*x1 = rand() % x; x2 = rand() % x; while (x2 == x1) { x2 = rand() % x; } y1 = rand() % y; y2 = rand() % y; while (y2 == y1) { y2 = rand() % y; }*/ V[0].PB(MP(min(x1, x2), max(x1, x2))); V[1].PB(MP(min(y1, y2), max(y1, y2))); } printf("%lld\n", (LL)solve(V[0], x) * solve(V[1], y)); 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 | #include <bits/stdc++.h> using namespace std; #define PII pair<int, int> #define PLL pair<LL, LL> #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 pb pop_back #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 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], " " const int M = 1024 * 1024; struct node { int mx, add, ile; }; int n, S[M]; PII T[M]; VPII Z; unordered_map<int, int> mapa; node D[2 * M]; int pp, kk, xx; inline void pchaj(int v) { D[2 * v].add += D[v].add; D[2 * v + 1].add += D[v].add; D[v].add = 0; } inline void popraw(int v) { int l = D[2 * v].mx + D[2 * v].add; int r = D[2 * v + 1].mx + D[2 * v + 1].add; D[v].mx = max(l, r); D[v].ile = 0; if (l == D[v].mx) { D[v].ile += D[2 * v].ile; } if (r == D[v].mx) { D[v].ile += D[2 * v + 1].ile; } } inline void add(int v, int vp, int vk) { if (pp > kk || vp > kk || vk < pp) { return; } if (vp >= pp && vk <= kk) { D[v].add += xx; return; } pchaj(v); int mid = (vp + vk) / 2; add(2 * v, vp, mid); add(2 * v + 1, mid + 1, vk); popraw(v); } int solve(VPII V, int m) { Z.clear(); mapa.clear(); FOR(i, 0, 2 * M - 1) { D[i] = node{0, 0, 0}; } VI X; FOR(i, 0, n - 1) { T[i + 1] = V[i]; Z.PB(MP(V[i].f, i + 1)); Z.PB(MP(V[i].s, -i - 1)); X.PB(V[i].f); X.PB(V[i].s); } X.PB(0); X.PB(m); sort(ALL(Z)); sort(ALL(X)); int prv = 0, tmp = 0; for (auto x : X) { if (x != prv) { S[tmp] = x - prv; prv = x; tmp++; mapa[prv] = tmp; } } FOR(i, 0, tmp - 1) { D[i + M].ile = S[i]; } FORD(i, M - 1, 0) { D[i].ile = D[2 * i].ile + D[2 * i + 1].ile; } for (auto& x : Z) { x.f = mapa[x.f]; if (x.s > 0) { T[x.s].f = x.f; } else { T[-x.s].s = x.f; } } //return 0; FOR(i, 1, n) { D[1].add++; pp = T[i].f; kk = T[i].s - 1; xx = -1; add(1, 0, M - 1); } int res = 0; if (D[1].mx + D[1].add == n) { maxi(res, D[1].ile); } for (auto x : Z) { if (x.s > 0) { D[1].add--; pp = T[x.s].f; kk = T[x.s].s - 1; xx = 2; add(1, 0, M - 1); } else { D[1].add++; pp = T[-x.s].f; kk = T[-x.s].s - 1; xx = -2; add(1, 0, M - 1); } if (D[1].mx + D[1].add == n) { maxi(res, D[1].ile); } } return res; } int32_t main() { //ios_base::sync_with_stdio(0); //cin.tie(NULL); int x, y; scanf("%d%d%d", &n, &x, &y); //n = 5e5; //x = 1e9; //y = 1e9; VPII V[2]; FOR(i, 1, n) { int x1, x2, y1, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2); /*x1 = rand() % x; x2 = rand() % x; while (x2 == x1) { x2 = rand() % x; } y1 = rand() % y; y2 = rand() % y; while (y2 == y1) { y2 = rand() % y; }*/ V[0].PB(MP(min(x1, x2), max(x1, x2))); V[1].PB(MP(min(y1, y2), max(y1, y2))); } printf("%lld\n", (LL)solve(V[0], x) * solve(V[1], y)); return 0; } |