#define make_pair mp #define emplace_back pb #include <bits/stdc++.h> using namespace std; const int N = 5e5 + 3, D = (1<<22) + 5, pods = (1<<21) - 1, INF = 2e9 + 10; int n, X, Y, xx[N], xxx[N], yy[N], yyy[N]; map<int, int> mapa; vector<int> tab[2*N]; int ansx, ansy, d[D]; void add(int x, int val) { x += pods; while(x) { d[x] += val; x /= 2; } } int suma(int x, int y) { if(x > y) return 1; x += pods; y += pods; int ans = d[x]; if(x != y) ans += d[y]; while(x / 2 != y / 2) { if(x % 2 == 0) ans += d[x+1]; if(y % 2 == 1) ans += d[y-1]; x /= 2; y /= 2; } return ans; } void clear() { for(int i=0;i<D;i++) d[i] = 0; } int pos[N][4]; int cnt[N]; int what[4*N]; int m; void add_num(int id, int x) { pos[id][cnt[id]] = x; cnt[id]++; } void swap_num(int id) { for(int i=0;i<3;i++) swap(pos[id][i], pos[id][i+1]); } void perform() { pos[0][0] = INF; pos[0][1] = INF; clear(); for(int i=1;i<=n;i++) sort(pos[i], pos[i] + 4); for(int i=1;i<=n;i++) { int x = pos[i][0]; int y = pos[i][1]; add(x, 1); add(y, -1); } for(int i=1;i<=m/2;i++) { if(i != 1) ansx = max(ansx, what[i] - what[i-1]); int x = 0; for(auto &z : tab[i]) if(pos[z][1] < pos[x][1]) x = z; int y = pos[x][1]; int sum = suma(i + 1, y - 1); if(sum == 0) { ansx = max(ansx, what[i+1] - what[i] + what[y] - what[y-1]); } for(auto x : tab[i]) { int z = pos[x][1]; int zz = pos[x][2]; add(z, 2); swap_num(x); add(zz, -1); } } for(int i=1;i<=n;i++) cnt[i] = 0; ansx = max(ansx, what[m/2+1] - what[m/2]); } int main() { scanf("%d%d%d", &n, &X, &Y); for(int i=1;i<=n;i++) { scanf("%d%d", &xxx[i], &yyy[i]); scanf("%d%d", &xx[i], &yy[i]); } for(int i=1;i<=n;i++) { mapa[xxx[i]] = 0; mapa[xx[i]] = 0; mapa[xxx[i] + X] = 0; mapa[xx[i] + X] = 0; } m = mapa.size(); int wsk = 0; for(auto &it : mapa) { wsk++; it.second = wsk; what[wsk] = it.first; } for(int i=1;i<=n;i++) { tab[mapa[xxx[i]]].pb(i); tab[mapa[xx[i]]].pb(i); add_num(i, mapa[xx[i]]); add_num(i, mapa[xxx[i]]); add_num(i, mapa[xx[i] + X]); add_num(i, mapa[xxx[i] + X]); } perform(); swap(ansx, ansy); mapa.clear(); for(int i=1;i<=m;i++) tab[i].clear(); for(int i=1;i<=n;i++) { mapa[yyy[i]] = 0; mapa[yy[i]] = 0; mapa[yyy[i] + Y] = 0; mapa[yy[i] + Y] = 0; } m = mapa.size(); wsk = 0; for(auto &it : mapa) { wsk++; it.second = wsk; what[wsk] = it.first; } for(int i=1;i<=n;i++) { tab[mapa[yyy[i]]].pb(i); tab[mapa[yy[i]]].pb(i); add_num(i, mapa[yy[i]]); add_num(i, mapa[yyy[i]]); add_num(i, mapa[yy[i] + Y]); add_num(i, mapa[yyy[i] + Y]); } perform(); long long ans = (long long)ansx * (long long)ansy; printf("%lld", ans); 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 | #define make_pair mp #define emplace_back pb #include <bits/stdc++.h> using namespace std; const int N = 5e5 + 3, D = (1<<22) + 5, pods = (1<<21) - 1, INF = 2e9 + 10; int n, X, Y, xx[N], xxx[N], yy[N], yyy[N]; map<int, int> mapa; vector<int> tab[2*N]; int ansx, ansy, d[D]; void add(int x, int val) { x += pods; while(x) { d[x] += val; x /= 2; } } int suma(int x, int y) { if(x > y) return 1; x += pods; y += pods; int ans = d[x]; if(x != y) ans += d[y]; while(x / 2 != y / 2) { if(x % 2 == 0) ans += d[x+1]; if(y % 2 == 1) ans += d[y-1]; x /= 2; y /= 2; } return ans; } void clear() { for(int i=0;i<D;i++) d[i] = 0; } int pos[N][4]; int cnt[N]; int what[4*N]; int m; void add_num(int id, int x) { pos[id][cnt[id]] = x; cnt[id]++; } void swap_num(int id) { for(int i=0;i<3;i++) swap(pos[id][i], pos[id][i+1]); } void perform() { pos[0][0] = INF; pos[0][1] = INF; clear(); for(int i=1;i<=n;i++) sort(pos[i], pos[i] + 4); for(int i=1;i<=n;i++) { int x = pos[i][0]; int y = pos[i][1]; add(x, 1); add(y, -1); } for(int i=1;i<=m/2;i++) { if(i != 1) ansx = max(ansx, what[i] - what[i-1]); int x = 0; for(auto &z : tab[i]) if(pos[z][1] < pos[x][1]) x = z; int y = pos[x][1]; int sum = suma(i + 1, y - 1); if(sum == 0) { ansx = max(ansx, what[i+1] - what[i] + what[y] - what[y-1]); } for(auto x : tab[i]) { int z = pos[x][1]; int zz = pos[x][2]; add(z, 2); swap_num(x); add(zz, -1); } } for(int i=1;i<=n;i++) cnt[i] = 0; ansx = max(ansx, what[m/2+1] - what[m/2]); } int main() { scanf("%d%d%d", &n, &X, &Y); for(int i=1;i<=n;i++) { scanf("%d%d", &xxx[i], &yyy[i]); scanf("%d%d", &xx[i], &yy[i]); } for(int i=1;i<=n;i++) { mapa[xxx[i]] = 0; mapa[xx[i]] = 0; mapa[xxx[i] + X] = 0; mapa[xx[i] + X] = 0; } m = mapa.size(); int wsk = 0; for(auto &it : mapa) { wsk++; it.second = wsk; what[wsk] = it.first; } for(int i=1;i<=n;i++) { tab[mapa[xxx[i]]].pb(i); tab[mapa[xx[i]]].pb(i); add_num(i, mapa[xx[i]]); add_num(i, mapa[xxx[i]]); add_num(i, mapa[xx[i] + X]); add_num(i, mapa[xxx[i] + X]); } perform(); swap(ansx, ansy); mapa.clear(); for(int i=1;i<=m;i++) tab[i].clear(); for(int i=1;i<=n;i++) { mapa[yyy[i]] = 0; mapa[yy[i]] = 0; mapa[yyy[i] + Y] = 0; mapa[yy[i] + Y] = 0; } m = mapa.size(); wsk = 0; for(auto &it : mapa) { wsk++; it.second = wsk; what[wsk] = it.first; } for(int i=1;i<=n;i++) { tab[mapa[yyy[i]]].pb(i); tab[mapa[yy[i]]].pb(i); add_num(i, mapa[yy[i]]); add_num(i, mapa[yyy[i]]); add_num(i, mapa[yy[i] + Y]); add_num(i, mapa[yyy[i] + Y]); } perform(); long long ans = (long long)ansx * (long long)ansy; printf("%lld", ans); return 0; } |