#include <bits/stdc++.h> #define PB push_back #define ST first #define ND second #define _ ios_base::sync_with_stdio(0); cin.tie(0); using namespace std; //mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); using ll = long long; using pi = pair<int,int>; using vi = vector<int>; const int nax = 500*1000+10,INF=1e9; int n,X,Y; pi linex[2*nax]; pi liney[2*nax]; int hsh[nax],maxX,maxY; int ansX=INF,ansY=INF; pair<ll,int>f[2*nax]; int main() {_ srand(time(NULL)); cin>>n>>X>>Y; for(int x1,y1,x2,y2,i=1; i<=n; i++) { cin>>x1>>y1>>x2>>y2; linex[2*i-1] = {min(x1,x2),i}; linex[2*i] = {max(x1,x2),-i}; liney[2*i] = {min(y1,y2),i}; liney[2*i-1] = {max(y1,y2),-i}; } sort(linex+1,linex+2*n+1); sort(liney+1,liney+2*n+1); linex[2*n+2] = {X,0}; liney[2*n+2] = {Y,0}; for(int q:{0,1}) { maxX=maxY=0; for(int i=1; i<=n; i++) { hsh[i] = rand()%INF; } ll act = 0; for(int i=1; i<=2*n+2; i++) { f[i-1] = {act,linex[i].ST-linex[i-1].ST}; if(linex[i].ND<0) { act-=hsh[-linex[i].ND]; } else { act+=hsh[linex[i].ND]; } } sort(f,f+2*n+2); int s = f[0].ND; for(int i=1; i<=2*n+1; i++) { if(f[i].ST!=f[i-1].ST) { maxX=max(maxX,s); s=0; } s+=f[i].ND; } maxX=max(maxX,s); act = 0; for(int i=1; i<=2*n+2; i++) { f[i-1] = {act,liney[i].ST-liney[i-1].ST}; if(liney[i].ND<0) { act-=hsh[-liney[i].ND]; } else { act+=hsh[liney[i].ND]; } } sort(f,f+2*n+2); s = f[0].ND; for(int i=1; i<=2*n+1; i++) { if(f[i].ST!=f[i-1].ST) { maxY=max(maxY,s); s=0; } s+=f[i].ND; } maxY=max(maxY,s); ansX=min(ansX,maxX); ansY=min(ansY,maxY); } cout<<(ll)ansX*ansY; }
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 | #include <bits/stdc++.h> #define PB push_back #define ST first #define ND second #define _ ios_base::sync_with_stdio(0); cin.tie(0); using namespace std; //mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); using ll = long long; using pi = pair<int,int>; using vi = vector<int>; const int nax = 500*1000+10,INF=1e9; int n,X,Y; pi linex[2*nax]; pi liney[2*nax]; int hsh[nax],maxX,maxY; int ansX=INF,ansY=INF; pair<ll,int>f[2*nax]; int main() {_ srand(time(NULL)); cin>>n>>X>>Y; for(int x1,y1,x2,y2,i=1; i<=n; i++) { cin>>x1>>y1>>x2>>y2; linex[2*i-1] = {min(x1,x2),i}; linex[2*i] = {max(x1,x2),-i}; liney[2*i] = {min(y1,y2),i}; liney[2*i-1] = {max(y1,y2),-i}; } sort(linex+1,linex+2*n+1); sort(liney+1,liney+2*n+1); linex[2*n+2] = {X,0}; liney[2*n+2] = {Y,0}; for(int q:{0,1}) { maxX=maxY=0; for(int i=1; i<=n; i++) { hsh[i] = rand()%INF; } ll act = 0; for(int i=1; i<=2*n+2; i++) { f[i-1] = {act,linex[i].ST-linex[i-1].ST}; if(linex[i].ND<0) { act-=hsh[-linex[i].ND]; } else { act+=hsh[linex[i].ND]; } } sort(f,f+2*n+2); int s = f[0].ND; for(int i=1; i<=2*n+1; i++) { if(f[i].ST!=f[i-1].ST) { maxX=max(maxX,s); s=0; } s+=f[i].ND; } maxX=max(maxX,s); act = 0; for(int i=1; i<=2*n+2; i++) { f[i-1] = {act,liney[i].ST-liney[i-1].ST}; if(liney[i].ND<0) { act-=hsh[-liney[i].ND]; } else { act+=hsh[liney[i].ND]; } } sort(f,f+2*n+2); s = f[0].ND; for(int i=1; i<=2*n+1; i++) { if(f[i].ST!=f[i-1].ST) { maxY=max(maxY,s); s=0; } s+=f[i].ND; } maxY=max(maxY,s); ansX=min(ansX,maxX); ansY=min(ansY,maxY); } cout<<(ll)ansX*ansY; } |