#include <cstdio>
#include <cstdint>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
const uint64_t P = 18393589780163810583UL;
struct event_t {
int x;
uint64_t hash;
bool start;
};
int calc_dim(vector<event_t>& evs, int L) {
map<uint64_t, int> cases;
uint64_t hashsum = 0;
int x = 0;
int next = evs[0].x;
if (next > 0) {
cases[0] = next;
}
for (int i = 0; i < evs.size(); ++i) {
next = (i == evs.size() - 1) ? L : evs[i + 1].x;
if (evs[i].start) {
hashsum += evs[i].hash;
}
else {
hashsum -= evs[i].hash;
}
if (evs[i].x != next) {
map<uint64_t, int>::iterator it = cases.find(hashsum);
if (it == cases.end()) {
cases[hashsum] = next - evs[i].x;
}
else {
(*it).second += next - evs[i].x;
}
}
}
int max_case = 0;
for (map<uint64_t, int>::iterator it = cases.begin(); it != cases.end(); it++) {
if (max_case < it->second) {
max_case = it->second;
}
}
return max_case;
}
bool cmp(const event_t& e1, const event_t& e2) {
if (e1.x < e2.x) {
return true;
}
return false;
}
int main () {
int n, i, X, Y, x1, x2, y1, y2;
scanf("%d %d %d", &n, &X, &Y);
vector<event_t> xevs, yevs;
xevs.reserve(2 * n + 8);
yevs.reserve(2 * n + 8);
uint64_t hash = 1;
for (i = 0; i < n; ++i) {
hash *= P;
event_t xev_start, xev_end, yev_start, yev_end;
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
xev_start.x = min(x1, x2);
xev_start.start = true;
xev_start.hash = hash;
xev_end.x = max(x1, x2);
xev_end.start = false;
xev_end.hash = hash;
yev_start.x = min(y1, y2);
yev_start.start = true;
yev_start.hash = hash;
yev_end.x = max(y1, y2);
yev_end.start = false;
yev_end.hash = hash;
xevs.push_back(xev_start);
xevs.push_back(xev_end);
yevs.push_back(yev_start);
yevs.push_back(yev_end);
}
sort(xevs.begin(), xevs.end(), cmp);
sort(yevs.begin(), yevs.end(), cmp);
printf("%lld\n", (int64_t)calc_dim(xevs, X) * (int64_t)calc_dim(yevs, 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 | #include <cstdio> #include <cstdint> #include <vector> #include <map> #include <algorithm> using namespace std; const uint64_t P = 18393589780163810583UL; struct event_t { int x; uint64_t hash; bool start; }; int calc_dim(vector<event_t>& evs, int L) { map<uint64_t, int> cases; uint64_t hashsum = 0; int x = 0; int next = evs[0].x; if (next > 0) { cases[0] = next; } for (int i = 0; i < evs.size(); ++i) { next = (i == evs.size() - 1) ? L : evs[i + 1].x; if (evs[i].start) { hashsum += evs[i].hash; } else { hashsum -= evs[i].hash; } if (evs[i].x != next) { map<uint64_t, int>::iterator it = cases.find(hashsum); if (it == cases.end()) { cases[hashsum] = next - evs[i].x; } else { (*it).second += next - evs[i].x; } } } int max_case = 0; for (map<uint64_t, int>::iterator it = cases.begin(); it != cases.end(); it++) { if (max_case < it->second) { max_case = it->second; } } return max_case; } bool cmp(const event_t& e1, const event_t& e2) { if (e1.x < e2.x) { return true; } return false; } int main () { int n, i, X, Y, x1, x2, y1, y2; scanf("%d %d %d", &n, &X, &Y); vector<event_t> xevs, yevs; xevs.reserve(2 * n + 8); yevs.reserve(2 * n + 8); uint64_t hash = 1; for (i = 0; i < n; ++i) { hash *= P; event_t xev_start, xev_end, yev_start, yev_end; scanf("%d %d %d %d", &x1, &y1, &x2, &y2); xev_start.x = min(x1, x2); xev_start.start = true; xev_start.hash = hash; xev_end.x = max(x1, x2); xev_end.start = false; xev_end.hash = hash; yev_start.x = min(y1, y2); yev_start.start = true; yev_start.hash = hash; yev_end.x = max(y1, y2); yev_end.start = false; yev_end.hash = hash; xevs.push_back(xev_start); xevs.push_back(xev_end); yevs.push_back(yev_start); yevs.push_back(yev_end); } sort(xevs.begin(), xevs.end(), cmp); sort(yevs.begin(), yevs.end(), cmp); printf("%lld\n", (int64_t)calc_dim(xevs, X) * (int64_t)calc_dim(yevs, Y)); return 0; } |
English