#include <bits/stdc++.h>
#define ll long long
#define mk std::make_pair
struct Event{
int type;
int x, y;
Event(){}
Event(int T, int X, int Y) : type(T), x(X), y(Y) {}
};
int n, X, Y;
std::vector<Event> A, B;
void input(){
std::cin >> n >> X >> Y;
int x1, y1, x2, y2;
for (int i = 1; i <= n; i++){
std::cin >> x1 >> y1 >> x2 >> y2;
if (x2 < x1)
std::swap(x1, x2);
if (y2 < y1)
std::swap(y1, y2);
A.emplace_back(0, x1, x2);
A.emplace_back(1, x2, x1);
B.emplace_back(0, y1, y2);
B.emplace_back(1, y2, y1);
}
A.emplace_back(0, 0, X); A.emplace_back(1, X, 0);
B.emplace_back(0, 0, Y); B.emplace_back(1, Y, 0);
}
bool cmp1(const Event &e1, const Event &e2){
return e1.x < e2.x;
}
std::map<std::pair<int, int>, int> res;
std::multiset<int> G, H;
// w G trzymam poczatki przedzialow ktore sie jeszcze nie skonczyly
// w H to samo tylko trzymam konce
ll solve(std::vector<Event> &e){
res.clear(); G.clear(); H.clear();
int l, r, j;
int i = 0;
G.insert(0);
H.insert(e.back().x);
while (i < e.size() && e[i].x < e.back().x){
j = i;
while (j < e.size()-1 && e[i].x == e[j+1].x)
j++;
for (int k = i; k <= j; k++){
if (e[k].type == 0){
G.insert(e[k].x);
H.insert(e[k].y);
}
else{
G.erase(G.find(e[k].y));
H.erase(H.find(e[k].x));
}
}
l = (*(G.rbegin()));
r = (*(H.begin()));
res[mk(l, r)] += e[j+1].x - e[i].x;
i = j+1;
}
int R = 0;
for (auto p: res)
R = std::max(R, p.second);
return R;
}
int main(){
std::ios_base::sync_with_stdio(0); std::cin.tie(NULL);
input();
std::sort(A.begin(), A.end(), cmp1);
std::sort(B.begin(), B.end(), cmp1);
ll x = solve(A);
ll y = solve(B);
std::cout << x*y << "\n";
}
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 | #include <bits/stdc++.h> #define ll long long #define mk std::make_pair struct Event{ int type; int x, y; Event(){} Event(int T, int X, int Y) : type(T), x(X), y(Y) {} }; int n, X, Y; std::vector<Event> A, B; void input(){ std::cin >> n >> X >> Y; int x1, y1, x2, y2; for (int i = 1; i <= n; i++){ std::cin >> x1 >> y1 >> x2 >> y2; if (x2 < x1) std::swap(x1, x2); if (y2 < y1) std::swap(y1, y2); A.emplace_back(0, x1, x2); A.emplace_back(1, x2, x1); B.emplace_back(0, y1, y2); B.emplace_back(1, y2, y1); } A.emplace_back(0, 0, X); A.emplace_back(1, X, 0); B.emplace_back(0, 0, Y); B.emplace_back(1, Y, 0); } bool cmp1(const Event &e1, const Event &e2){ return e1.x < e2.x; } std::map<std::pair<int, int>, int> res; std::multiset<int> G, H; // w G trzymam poczatki przedzialow ktore sie jeszcze nie skonczyly // w H to samo tylko trzymam konce ll solve(std::vector<Event> &e){ res.clear(); G.clear(); H.clear(); int l, r, j; int i = 0; G.insert(0); H.insert(e.back().x); while (i < e.size() && e[i].x < e.back().x){ j = i; while (j < e.size()-1 && e[i].x == e[j+1].x) j++; for (int k = i; k <= j; k++){ if (e[k].type == 0){ G.insert(e[k].x); H.insert(e[k].y); } else{ G.erase(G.find(e[k].y)); H.erase(H.find(e[k].x)); } } l = (*(G.rbegin())); r = (*(H.begin())); res[mk(l, r)] += e[j+1].x - e[i].x; i = j+1; } int R = 0; for (auto p: res) R = std::max(R, p.second); return R; } int main(){ std::ios_base::sync_with_stdio(0); std::cin.tie(NULL); input(); std::sort(A.begin(), A.end(), cmp1); std::sort(B.begin(), B.end(), cmp1); ll x = solve(A); ll y = solve(B); std::cout << x*y << "\n"; } |
English