#include <bits/stdc++.h> #define FOR(i, a, b) for (int i=(a); i<(b); i++) #define PPC(x) __builtin_popcountll((x)) #define ALL(x) (x).begin(), (x).end() #define pb push_back #define st first #define nd second using namespace std; const int maxN = 1 << 19, maxTS = maxN * 4, p = 5; long long mod = 1000000000000000031ll; inline void addMod(long long& a, long long b) { a = (a + b) % mod; } inline void multMod(long long& a, long long b) { a = a * b % mod; } struct Tree { int offset, qbegin, qend; long long T[maxTS], x; void qpriv(int v, int left, int right) { if (left >= qend or right <= qbegin) return; if (left >= qbegin and right <= qend) { addMod(T[v], x); return; } qpriv(v * 2, left, (left + right) / 2); qpriv(v*2+1, (left + right) / 2, right); } void resize(int n) { for (offset = 1; offset < n; offset *= 2); } void add(int a, int b, long long c) { qbegin = a + offset; qend = b + offset; x = c; qpriv(1, offset, offset * 2); } long long* fillH() { FOR(i, 1, offset) addMod(T[i * 2], T[i]), addMod(T[i*2+1], T[i]); return T + offset; } }tr[2]; int vals[maxN * 2]; pair <long long, int> T[maxN * 2]; int fillVals(pair <int, int>* x, int n) { int s = 0; FOR(i, 0, n) { if (x[i].nd < x[i].st) swap(x[i].st, x[i].nd); vals[s++] = x[i].st; vals[s++] = x[i].nd; } sort(vals, vals + s); return unique(vals, vals + s) - vals; } int f(pair <int, int>* x, int n, int X, Tree& tree, map <int, int>& renum) { int vs = fillVals(x, n); FOR(i, 0, vs) renum[vals[i]] = i; long long ppow = 1ll; tree.resize(vs); random_shuffle(x, x + n); FOR(i, 0, n) { int a = renum[x[i].st], b = renum[x[i].nd]; tree.add(a, b, ppow); multMod(ppow, p); } long long* H = tree.fillH(); vals[vs] = X + vals[0]; FOR(i, 0, vs) T[i] = {H[i], vals[i+1] - vals[i]}; sort(T, T + vs); int res = 0, temp = 0; FOR(i, 0, vs) { temp += T[i].nd; if (i+1 == vs or T[i+1].st != T[i].st) res = max(res, temp), temp = 0; } return res; } pair <int, int> X[maxN], Y[maxN]; map <int, int> renumX, renumY; int main() { int n, x, y; scanf ("%d%d%d", &n, &x, &y); FOR(i, 0, n) { int in[4]; FOR(j, 0, 4) scanf ("%d", in+j); X[i] = {in[0], in[2]}; Y[i] = {in[1], in[3]}; } long long a = f(X, n, x, tr[0], renumX); long long b = f(Y, n, y, tr[1], renumY); printf("%lld\n", a * b); 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 | #include <bits/stdc++.h> #define FOR(i, a, b) for (int i=(a); i<(b); i++) #define PPC(x) __builtin_popcountll((x)) #define ALL(x) (x).begin(), (x).end() #define pb push_back #define st first #define nd second using namespace std; const int maxN = 1 << 19, maxTS = maxN * 4, p = 5; long long mod = 1000000000000000031ll; inline void addMod(long long& a, long long b) { a = (a + b) % mod; } inline void multMod(long long& a, long long b) { a = a * b % mod; } struct Tree { int offset, qbegin, qend; long long T[maxTS], x; void qpriv(int v, int left, int right) { if (left >= qend or right <= qbegin) return; if (left >= qbegin and right <= qend) { addMod(T[v], x); return; } qpriv(v * 2, left, (left + right) / 2); qpriv(v*2+1, (left + right) / 2, right); } void resize(int n) { for (offset = 1; offset < n; offset *= 2); } void add(int a, int b, long long c) { qbegin = a + offset; qend = b + offset; x = c; qpriv(1, offset, offset * 2); } long long* fillH() { FOR(i, 1, offset) addMod(T[i * 2], T[i]), addMod(T[i*2+1], T[i]); return T + offset; } }tr[2]; int vals[maxN * 2]; pair <long long, int> T[maxN * 2]; int fillVals(pair <int, int>* x, int n) { int s = 0; FOR(i, 0, n) { if (x[i].nd < x[i].st) swap(x[i].st, x[i].nd); vals[s++] = x[i].st; vals[s++] = x[i].nd; } sort(vals, vals + s); return unique(vals, vals + s) - vals; } int f(pair <int, int>* x, int n, int X, Tree& tree, map <int, int>& renum) { int vs = fillVals(x, n); FOR(i, 0, vs) renum[vals[i]] = i; long long ppow = 1ll; tree.resize(vs); random_shuffle(x, x + n); FOR(i, 0, n) { int a = renum[x[i].st], b = renum[x[i].nd]; tree.add(a, b, ppow); multMod(ppow, p); } long long* H = tree.fillH(); vals[vs] = X + vals[0]; FOR(i, 0, vs) T[i] = {H[i], vals[i+1] - vals[i]}; sort(T, T + vs); int res = 0, temp = 0; FOR(i, 0, vs) { temp += T[i].nd; if (i+1 == vs or T[i+1].st != T[i].st) res = max(res, temp), temp = 0; } return res; } pair <int, int> X[maxN], Y[maxN]; map <int, int> renumX, renumY; int main() { int n, x, y; scanf ("%d%d%d", &n, &x, &y); FOR(i, 0, n) { int in[4]; FOR(j, 0, 4) scanf ("%d", in+j); X[i] = {in[0], in[2]}; Y[i] = {in[1], in[3]}; } long long a = f(X, n, x, tr[0], renumX); long long b = f(Y, n, y, tr[1], renumY); printf("%lld\n", a * b); return 0; } |