#include<bits/stdc++.h> using namespace std; using lld = long long; const lld P = 1e9+696969; const lld Q = 7; int solve(vector<pair<int,int> >& t, int X){ for(auto& i : t) if(i.first > i.second) swap(i.first,i.second); vector<pair<int,lld> > e; e.reserve(2*t.size()+2); lld q=1; for(int i=0;i<t.size();i++){ e.push_back({t[i].first, q}); e.push_back({t[i].second, P-q}); q = (q*Q) % P; } e.push_back({0,0}); e.push_back({X,0}); sort(e.begin(), e.end()); vector<pair<lld,int> > p; p.reserve(2*t.size()+1); lld l=e[0].second; for(int i=1;i<e.size();i++){ p.push_back({l,e[i].first-e[i-1].first}); l += e[i].second; l %= P; } sort(p.begin(), p.end()); int res = 0; int sum = 0; lld val = -1; for(auto& i : p){ if(i.first != val){ sum = 0; val = i.first; } sum += i.second; res = max(res, sum); } return res; } int main(void){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n,X,Y; cin >> n >> X >> Y; vector<pair<int,int> > a(n), b(n); for(int i=0;i<n;i++) cin >> a[i].first >> b[i].first >> a[i].second >> b[i].second; int x = solve(a,X); int y = solve(b,Y); cout << (lld) x * (lld) y << "\n"; 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 | #include<bits/stdc++.h> using namespace std; using lld = long long; const lld P = 1e9+696969; const lld Q = 7; int solve(vector<pair<int,int> >& t, int X){ for(auto& i : t) if(i.first > i.second) swap(i.first,i.second); vector<pair<int,lld> > e; e.reserve(2*t.size()+2); lld q=1; for(int i=0;i<t.size();i++){ e.push_back({t[i].first, q}); e.push_back({t[i].second, P-q}); q = (q*Q) % P; } e.push_back({0,0}); e.push_back({X,0}); sort(e.begin(), e.end()); vector<pair<lld,int> > p; p.reserve(2*t.size()+1); lld l=e[0].second; for(int i=1;i<e.size();i++){ p.push_back({l,e[i].first-e[i-1].first}); l += e[i].second; l %= P; } sort(p.begin(), p.end()); int res = 0; int sum = 0; lld val = -1; for(auto& i : p){ if(i.first != val){ sum = 0; val = i.first; } sum += i.second; res = max(res, sum); } return res; } int main(void){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n,X,Y; cin >> n >> X >> Y; vector<pair<int,int> > a(n), b(n); for(int i=0;i<n;i++) cin >> a[i].first >> b[i].first >> a[i].second >> b[i].second; int x = solve(a,X); int y = solve(b,Y); cout << (lld) x * (lld) y << "\n"; return 0; } |