#include <bits/stdc++.h> // #pragma GCC optimize ("O3") // #pragma GCC target ("sse4") using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> PII; #define REP(i,n) for(int i=0;i<(n);++i) #define FOR(i,a,b) for (int i=(a); i<(b); ++i) #define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i) #define MAX(dst,src) dst = max(dst, (src)) #define MIN(dst,src) dst = min(dst, (src)) #define pb push_back #define mp make_pair #define st first #define nd second const LL MOD = 226164873694399LL; const int P = 67; LL hashes[500005]; LL get(int X, vector<PII> xs) { vector<PII> events; REP(i,xs.size()) { events.pb({xs[i].st, i}); events.pb({xs[i].nd, i}); } sort(events.begin(), events.end()); vector<pair<LL, int>> results; int k = 0; int lastX = 0; LL hash = 0; vector<bool> selected(xs.size()); while (k < events.size()) { results.pb({hash, events[k].st - lastX}); lastX = events[k].st; while (k < events.size() && events[k].st == lastX) { if (selected[events[k].nd]) hash += MOD - hashes[events[k].nd]; else hash += hashes[events[k].nd]; hash %= MOD; selected[events[k].nd] = !selected[events[k].nd]; ++k; } } results.pb({hash, X - lastX}); int result = 0; sort(results.begin(), results.end()); int curresult = 0; LL curhash = -1; for (auto p: results) { if (p.st != curhash) { curhash = p.st; curresult = 0; } curresult += p.nd; MAX(result, curresult); } return result; } int main(int argc, char* argv[]) { hashes[0] = 1; FOR(i,1,500001) hashes[i] = hashes[i-1] * P % MOD; int N, X, Y; scanf("%d%d%d", &N, &X, &Y); vector<PII> xs, ys; REP(i,N) { int x1,y1,x2,y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2); xs.pb({x1, x2}); ys.pb({y1, y2}); } LL result = get(X, xs) * get(Y, ys); printf("%lld\n", result); }
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> // #pragma GCC optimize ("O3") // #pragma GCC target ("sse4") using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> PII; #define REP(i,n) for(int i=0;i<(n);++i) #define FOR(i,a,b) for (int i=(a); i<(b); ++i) #define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i) #define MAX(dst,src) dst = max(dst, (src)) #define MIN(dst,src) dst = min(dst, (src)) #define pb push_back #define mp make_pair #define st first #define nd second const LL MOD = 226164873694399LL; const int P = 67; LL hashes[500005]; LL get(int X, vector<PII> xs) { vector<PII> events; REP(i,xs.size()) { events.pb({xs[i].st, i}); events.pb({xs[i].nd, i}); } sort(events.begin(), events.end()); vector<pair<LL, int>> results; int k = 0; int lastX = 0; LL hash = 0; vector<bool> selected(xs.size()); while (k < events.size()) { results.pb({hash, events[k].st - lastX}); lastX = events[k].st; while (k < events.size() && events[k].st == lastX) { if (selected[events[k].nd]) hash += MOD - hashes[events[k].nd]; else hash += hashes[events[k].nd]; hash %= MOD; selected[events[k].nd] = !selected[events[k].nd]; ++k; } } results.pb({hash, X - lastX}); int result = 0; sort(results.begin(), results.end()); int curresult = 0; LL curhash = -1; for (auto p: results) { if (p.st != curhash) { curhash = p.st; curresult = 0; } curresult += p.nd; MAX(result, curresult); } return result; } int main(int argc, char* argv[]) { hashes[0] = 1; FOR(i,1,500001) hashes[i] = hashes[i-1] * P % MOD; int N, X, Y; scanf("%d%d%d", &N, &X, &Y); vector<PII> xs, ys; REP(i,N) { int x1,y1,x2,y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2); xs.pb({x1, x2}); ys.pb({y1, y2}); } LL result = get(X, xs) * get(Y, ys); printf("%lld\n", result); } |