#include <bits/stdc++.h> using namespace std; #define FOR(i,x,y) for(int i=(int)(x);i<(int)(y);++i) #define FORE(i,x,y) for(int i=(int)(x);i<=(int)(y);++i) #define FORD(i,x,y) for(int i=(int)(x);i>=(int)(y);--i) #define PB push_back #define MP make_pair #define ST first #define ND second typedef long long ll; typedef pair<int,int> pii; const int MAXN=5e5+6; const int INF=1e9+1000; int n,X,Y; int ansa=0,ansb=0; pii a[MAXN]; pii b[MAXN]; int sa,sb; int mia=INF,mib=INF; int mxa=-1,mxb=-1; int resa[MAXN]; int resb[MAXN]; pii ca[MAXN]; pii cb[MAXN]; int main() { ios_base::sync_with_stdio(false);cin.tie(0); cin>>n>>X>>Y; FOR(i,0,n){ cin>>a[i].ST>>b[i].ST>>a[i].ND>>b[i].ND; /*if(a[i].ST==0)a[i].ST=X; if(a[i].ND==0)a[i].ND=Y; if(b[i].ST==0)b[i].ST=X; if(b[i].ND==0)b[i].ND=Y;*/ if(a[i].ST>a[i].ND)swap(a[i].ST,a[i].ND); if(b[i].ST>b[i].ND)swap(b[i].ST,b[i].ND); mia=min(mia,a[i].ST); mxa=max(mxa,a[i].ND); mib=min(mib,b[i].ST); mxb=max(mxb,b[i].ND); ca[i]=a[i]; cb[i]=b[i]; } sort(a,a+n); sort(b,b+n); sort(ca,ca+n); sort(cb,cb+n); int na=0; int nb=0; FOR(i,1,n){ if(ca[i].ND>ca[na].ND){ ca[++na]=ca[i]; if(ca[na-1].ND>ca[na].ST){ ca[na-1].ND=ca[na].ND; --na; } } } ++na; FOR(i,1,n){ if(cb[i].ND>cb[nb].ND){ cb[++nb]=cb[i]; if(cb[nb-1].ND>cb[nb].ST){ cb[nb-1].ND=cb[nb].ND; --nb; } } } ++nb; sa=mia+X-mxa; sb=mib+Y-mxb; int mxL=a[0].ST; multiset<int> lp; multiset<int,greater<int> > pp; multiset<int,greater<int> >::iterator it; priority_queue<int,vector<int>,greater<int> > zk; priority_queue<int,vector<int>,greater<int> > ptm; FOR(i,0,n){ if(mxL<a[i].ST)sa+=a[i].ST-mxL; mxL=max(mxL,a[i].ND); lp.insert(a[i].ST); pp.insert(a[i].ND); } int j=0; FOR(i,0,n){ lp.erase(lp.find(a[i].ST)); pp.erase(pp.find(a[i].ND)); while(j<n&&a[j].ST==a[i].ST)zk.push(a[j].ND),++j; while(zk.size()>0&&zk.top()<=a[i].ST)zk.pop(); if(lp.empty()){ ansa=max(ansa,zk.top()-a[i].ST); }else{ int posp=lower_bound(ca,ca+na,a[i])-ca; posp=ca[posp].ND; it=pp.lower_bound(posp); if(it==pp.end()){ ansa=max(ansa,min(*lp.begin(),zk.top())-a[i].ST); }else{ ansa=max(ansa,min(a[i].ND-a[i].ST,max(0,min(*lp.begin(),zk.top())-a[i].ST)+max(0,min(a[i].ND,zk.top())-*it))); ansa=max(ansa,min(*lp.begin(),zk.top())-a[i].ST); } } ptm.push(a[i].ND); while(ptm.size()>0&&(i+1>=n||ptm.top()<a[i+1].ST)){ while(zk.size()>0&&zk.top()<=ptm.top())zk.pop(); int x=INF; if(!lp.empty())x=min(x,*lp.begin()); if(!zk.empty())x=min(x,zk.top()); if(i+1<n)x=min(x,a[i+1].ST); if(x==INF)x=-1; ansa=max(ansa,x-ptm.top()); ptm.pop(); } } mxL=b[0].ST; lp.clear(); pp.clear(); while(!zk.empty())zk.pop(); while(!ptm.empty())ptm.pop(); FOR(i,0,n){ if(mxL<b[i].ST)sb+=b[i].ST-mxL; mxL=max(mxL,b[i].ND); lp.insert(b[i].ST); pp.insert(b[i].ND); } j=0; FOR(i,0,n){ lp.erase(lp.find(b[i].ST)); pp.erase(pp.find(b[i].ND)); while(j<n&&b[j].ST==b[i].ST)zk.push(b[j].ND),++j; while(zk.size()>0&&zk.top()<=b[i].ST)zk.pop(); if(lp.empty()){ ansb=max(ansb,zk.top()-b[i].ST); }else{ int posp=lower_bound(cb,cb+nb,b[i])-cb; posp=cb[posp].ND; it=pp.lower_bound(posp); if(it==pp.end()){ ansb=max(ansb,min(*lp.begin(),zk.top())-b[i].ST); }else{ ansb=max(ansb,min(b[i].ND-b[i].ST,max(0,min(*lp.begin(),zk.top())-b[i].ST)+max(0,min(b[i].ND,zk.top())-*it))); ansb=max(ansb,min(*lp.begin(),zk.top())-b[i].ST); } } ptm.push(b[i].ND); while(ptm.size()>0&&(i+1>=n||ptm.top()<b[i+1].ST)){ while(zk.size()>0&&zk.top()<=ptm.top())zk.pop(); int x=INF; if(!lp.empty())x=min(x,*lp.begin()); if(!zk.empty())x=min(x,zk.top()); if(i+1<n)x=min(x,b[i+1].ST); if(x==INF)x=-1; ansb=max(ansb,x-ptm.top()); ptm.pop(); } } cout<<(ll)max(ansa,sa)*(ll)max(ansb,sb)<<"\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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | #include <bits/stdc++.h> using namespace std; #define FOR(i,x,y) for(int i=(int)(x);i<(int)(y);++i) #define FORE(i,x,y) for(int i=(int)(x);i<=(int)(y);++i) #define FORD(i,x,y) for(int i=(int)(x);i>=(int)(y);--i) #define PB push_back #define MP make_pair #define ST first #define ND second typedef long long ll; typedef pair<int,int> pii; const int MAXN=5e5+6; const int INF=1e9+1000; int n,X,Y; int ansa=0,ansb=0; pii a[MAXN]; pii b[MAXN]; int sa,sb; int mia=INF,mib=INF; int mxa=-1,mxb=-1; int resa[MAXN]; int resb[MAXN]; pii ca[MAXN]; pii cb[MAXN]; int main() { ios_base::sync_with_stdio(false);cin.tie(0); cin>>n>>X>>Y; FOR(i,0,n){ cin>>a[i].ST>>b[i].ST>>a[i].ND>>b[i].ND; /*if(a[i].ST==0)a[i].ST=X; if(a[i].ND==0)a[i].ND=Y; if(b[i].ST==0)b[i].ST=X; if(b[i].ND==0)b[i].ND=Y;*/ if(a[i].ST>a[i].ND)swap(a[i].ST,a[i].ND); if(b[i].ST>b[i].ND)swap(b[i].ST,b[i].ND); mia=min(mia,a[i].ST); mxa=max(mxa,a[i].ND); mib=min(mib,b[i].ST); mxb=max(mxb,b[i].ND); ca[i]=a[i]; cb[i]=b[i]; } sort(a,a+n); sort(b,b+n); sort(ca,ca+n); sort(cb,cb+n); int na=0; int nb=0; FOR(i,1,n){ if(ca[i].ND>ca[na].ND){ ca[++na]=ca[i]; if(ca[na-1].ND>ca[na].ST){ ca[na-1].ND=ca[na].ND; --na; } } } ++na; FOR(i,1,n){ if(cb[i].ND>cb[nb].ND){ cb[++nb]=cb[i]; if(cb[nb-1].ND>cb[nb].ST){ cb[nb-1].ND=cb[nb].ND; --nb; } } } ++nb; sa=mia+X-mxa; sb=mib+Y-mxb; int mxL=a[0].ST; multiset<int> lp; multiset<int,greater<int> > pp; multiset<int,greater<int> >::iterator it; priority_queue<int,vector<int>,greater<int> > zk; priority_queue<int,vector<int>,greater<int> > ptm; FOR(i,0,n){ if(mxL<a[i].ST)sa+=a[i].ST-mxL; mxL=max(mxL,a[i].ND); lp.insert(a[i].ST); pp.insert(a[i].ND); } int j=0; FOR(i,0,n){ lp.erase(lp.find(a[i].ST)); pp.erase(pp.find(a[i].ND)); while(j<n&&a[j].ST==a[i].ST)zk.push(a[j].ND),++j; while(zk.size()>0&&zk.top()<=a[i].ST)zk.pop(); if(lp.empty()){ ansa=max(ansa,zk.top()-a[i].ST); }else{ int posp=lower_bound(ca,ca+na,a[i])-ca; posp=ca[posp].ND; it=pp.lower_bound(posp); if(it==pp.end()){ ansa=max(ansa,min(*lp.begin(),zk.top())-a[i].ST); }else{ ansa=max(ansa,min(a[i].ND-a[i].ST,max(0,min(*lp.begin(),zk.top())-a[i].ST)+max(0,min(a[i].ND,zk.top())-*it))); ansa=max(ansa,min(*lp.begin(),zk.top())-a[i].ST); } } ptm.push(a[i].ND); while(ptm.size()>0&&(i+1>=n||ptm.top()<a[i+1].ST)){ while(zk.size()>0&&zk.top()<=ptm.top())zk.pop(); int x=INF; if(!lp.empty())x=min(x,*lp.begin()); if(!zk.empty())x=min(x,zk.top()); if(i+1<n)x=min(x,a[i+1].ST); if(x==INF)x=-1; ansa=max(ansa,x-ptm.top()); ptm.pop(); } } mxL=b[0].ST; lp.clear(); pp.clear(); while(!zk.empty())zk.pop(); while(!ptm.empty())ptm.pop(); FOR(i,0,n){ if(mxL<b[i].ST)sb+=b[i].ST-mxL; mxL=max(mxL,b[i].ND); lp.insert(b[i].ST); pp.insert(b[i].ND); } j=0; FOR(i,0,n){ lp.erase(lp.find(b[i].ST)); pp.erase(pp.find(b[i].ND)); while(j<n&&b[j].ST==b[i].ST)zk.push(b[j].ND),++j; while(zk.size()>0&&zk.top()<=b[i].ST)zk.pop(); if(lp.empty()){ ansb=max(ansb,zk.top()-b[i].ST); }else{ int posp=lower_bound(cb,cb+nb,b[i])-cb; posp=cb[posp].ND; it=pp.lower_bound(posp); if(it==pp.end()){ ansb=max(ansb,min(*lp.begin(),zk.top())-b[i].ST); }else{ ansb=max(ansb,min(b[i].ND-b[i].ST,max(0,min(*lp.begin(),zk.top())-b[i].ST)+max(0,min(b[i].ND,zk.top())-*it))); ansb=max(ansb,min(*lp.begin(),zk.top())-b[i].ST); } } ptm.push(b[i].ND); while(ptm.size()>0&&(i+1>=n||ptm.top()<b[i+1].ST)){ while(zk.size()>0&&zk.top()<=ptm.top())zk.pop(); int x=INF; if(!lp.empty())x=min(x,*lp.begin()); if(!zk.empty())x=min(x,zk.top()); if(i+1<n)x=min(x,b[i+1].ST); if(x==INF)x=-1; ansb=max(ansb,x-ptm.top()); ptm.pop(); } } cout<<(ll)max(ansa,sa)*(ll)max(ansb,sb)<<"\n"; return 0; } |