#include <iostream> #include <sstream> #include <fstream> #include <string> #include <vector> #include <queue> #include <algorithm> #include <map> #include <set> #include <bitset> using namespace std; typedef unsigned long long LL; #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define ABS(val) ((val) < 0 ? -(val) : (val)) #define FOR(x, b, e) for(int x = b; x <= (e); ++x) #define FORD(x, b, e) for(int x = b; x >= (e); --x) #define REP(x, n) for(int x = 0; x < (n); ++x) #define VAR(v, n) __typeof(n) v = (n) #define ALL(c) (c).begin(), (c).end() #define SIZE(x) ((int)(x).size()) #define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define PB push_back #define ST first #define ND second #define M 1000000007ULL /* PA2019 "TER" */ struct p { int x; int y; int nr; bool is_end; bool is_endy; }; bool cmp_x(const struct p &p1, const struct p &p2) { return (p1.x < p2.x); } bool cmp_y(const struct p &p1, const struct p &p2) { return (p1.y < p2.y); } int seg [500100] = {}; int segy [500100] = {}; int main() { int n, X, Y; scanf("%d %d %d\n", &n ,&X, &Y); vector<p> pts; REP(i, n) { int x1, y1, x2, y2; scanf("%d %d %d %d", &x1, &y1, &x2, &y2); p p1; p1.x = x1; p1.y = y1; p1.nr = i; p p2; p2.x = x2; p2.y = y2; p2.nr = i; if (x1 < x2) { p1.is_end = false; p2.is_end = true; } else { p1.is_end = true; p2.is_end = false; } if (y1 < y2) { p1.is_endy = false; p2.is_endy = true; } else { p1.is_endy = true; p2.is_endy = false; } pts.PB(p1); pts.PB(p2); } sort(ALL(pts), cmp_x); /* REP(i, 2 * n){ printf("nr %d, is end %d, x %d, y %d\n", pts[i].nr, pts[i].is_end, pts[i].x, pts[i].y); } */ int last_x = 0; vector <int> codes; codes.PB(-1); VAR(p, pts.begin()); while (p != pts.end()) { int x = p->x; seg[codes.back() + 1] += x - last_x; /* REP(i, 5) printf("S %d\n", seg[i]); */ while (p != pts.end() && p->x == x) { //printf("px %d, nr %d\n", p->x, p->nr); if (p->is_end) { //rem nr codes.erase(std::remove(ALL(codes), p->nr), codes.end()); } else { codes.PB(p->nr); } p++; } last_x = x; /* FOREACH(v, codes) printf("%d, last_x %d\n", *v, last_x); */ } //assert(codes.size() == 1); //REP(i, 5) // printf("S %d\n", seg[i]); seg[0] += (X - last_x); //REP(i, 5) // printf("S %d\n", seg[i]); int x_max = -1; REP (i, n + 5) { x_max = MAX(x_max, seg[i]); } //////////////////// sort(ALL(pts), cmp_y); /* REP(i, 2 * n){ printf("nr %d, is end %d, x %d, y %d\n", pts[i].nr, pts[i].is_end, pts[i].x, pts[i].y); } */ int last_y = 0; vector <int> codesy; codesy.PB(-1); p = pts.begin(); while (p != pts.end()) { int y = p->y; segy[codesy.back() + 1] += y - last_y; /* REP(i, 5) printf("S %d\n", seg[i]); */ while (p != pts.end() && p->y == y) { //printf("px %d, nr %d\n", p->x, p->nr); if (p->is_endy) { //rem nr codesy.erase(std::remove(ALL(codesy), p->nr), codesy.end()); } else { codesy.PB(p->nr); } p++; } last_y = y; /* FOREACH(v, codes) printf("%d, last_x %d\n", *v, last_x); */ } //assert(codes.size() == 1); //REP(i, 5) // printf("S %d\n", seg[i]); segy[0] += (Y - last_y); //REP(i, 5) // printf("S %d\n", seg[i]); int y_max = -1; REP (i, n + 5) { y_max = MAX(y_max, segy[i]); } LL xmax = x_max; LL ymax = y_max; printf("%lld\n", xmax * ymax); 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 | #include <iostream> #include <sstream> #include <fstream> #include <string> #include <vector> #include <queue> #include <algorithm> #include <map> #include <set> #include <bitset> using namespace std; typedef unsigned long long LL; #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define ABS(val) ((val) < 0 ? -(val) : (val)) #define FOR(x, b, e) for(int x = b; x <= (e); ++x) #define FORD(x, b, e) for(int x = b; x >= (e); --x) #define REP(x, n) for(int x = 0; x < (n); ++x) #define VAR(v, n) __typeof(n) v = (n) #define ALL(c) (c).begin(), (c).end() #define SIZE(x) ((int)(x).size()) #define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define PB push_back #define ST first #define ND second #define M 1000000007ULL /* PA2019 "TER" */ struct p { int x; int y; int nr; bool is_end; bool is_endy; }; bool cmp_x(const struct p &p1, const struct p &p2) { return (p1.x < p2.x); } bool cmp_y(const struct p &p1, const struct p &p2) { return (p1.y < p2.y); } int seg [500100] = {}; int segy [500100] = {}; int main() { int n, X, Y; scanf("%d %d %d\n", &n ,&X, &Y); vector<p> pts; REP(i, n) { int x1, y1, x2, y2; scanf("%d %d %d %d", &x1, &y1, &x2, &y2); p p1; p1.x = x1; p1.y = y1; p1.nr = i; p p2; p2.x = x2; p2.y = y2; p2.nr = i; if (x1 < x2) { p1.is_end = false; p2.is_end = true; } else { p1.is_end = true; p2.is_end = false; } if (y1 < y2) { p1.is_endy = false; p2.is_endy = true; } else { p1.is_endy = true; p2.is_endy = false; } pts.PB(p1); pts.PB(p2); } sort(ALL(pts), cmp_x); /* REP(i, 2 * n){ printf("nr %d, is end %d, x %d, y %d\n", pts[i].nr, pts[i].is_end, pts[i].x, pts[i].y); } */ int last_x = 0; vector <int> codes; codes.PB(-1); VAR(p, pts.begin()); while (p != pts.end()) { int x = p->x; seg[codes.back() + 1] += x - last_x; /* REP(i, 5) printf("S %d\n", seg[i]); */ while (p != pts.end() && p->x == x) { //printf("px %d, nr %d\n", p->x, p->nr); if (p->is_end) { //rem nr codes.erase(std::remove(ALL(codes), p->nr), codes.end()); } else { codes.PB(p->nr); } p++; } last_x = x; /* FOREACH(v, codes) printf("%d, last_x %d\n", *v, last_x); */ } //assert(codes.size() == 1); //REP(i, 5) // printf("S %d\n", seg[i]); seg[0] += (X - last_x); //REP(i, 5) // printf("S %d\n", seg[i]); int x_max = -1; REP (i, n + 5) { x_max = MAX(x_max, seg[i]); } //////////////////// sort(ALL(pts), cmp_y); /* REP(i, 2 * n){ printf("nr %d, is end %d, x %d, y %d\n", pts[i].nr, pts[i].is_end, pts[i].x, pts[i].y); } */ int last_y = 0; vector <int> codesy; codesy.PB(-1); p = pts.begin(); while (p != pts.end()) { int y = p->y; segy[codesy.back() + 1] += y - last_y; /* REP(i, 5) printf("S %d\n", seg[i]); */ while (p != pts.end() && p->y == y) { //printf("px %d, nr %d\n", p->x, p->nr); if (p->is_endy) { //rem nr codesy.erase(std::remove(ALL(codesy), p->nr), codesy.end()); } else { codesy.PB(p->nr); } p++; } last_y = y; /* FOREACH(v, codes) printf("%d, last_x %d\n", *v, last_x); */ } //assert(codes.size() == 1); //REP(i, 5) // printf("S %d\n", seg[i]); segy[0] += (Y - last_y); //REP(i, 5) // printf("S %d\n", seg[i]); int y_max = -1; REP (i, n + 5) { y_max = MAX(y_max, segy[i]); } LL xmax = x_max; LL ymax = y_max; printf("%lld\n", xmax * ymax); return 0; } |