//created by Albert Mosialek #include<bits/stdc++.h> using namespace std; int n,X,Y, currentId; long long poleX, poleY, pole; int poleXInt, poleYInt; struct LabeledPoint{int l; int id;}; LabeledPoint xPoints[1000001]; LabeledPoint yPoints[1000001]; bool visited[1000001]; int idToHash[500001]; map<int, int> HashToArea; const int prime = 982451653; bool LabeledPointComparator( LabeledPoint first, LabeledPoint second) { return first.l < second.l; } int xD(LabeledPoint* points, int L){ HashToArea.clear(); //cerr<<HashToArea[0]<<endl; int poleInt = 0; int n2=2*n; sort(points, points+n2, LabeledPointComparator); int currentHash = 0; HashToArea[currentHash] = points[0].l; currentHash += idToHash[points[0].id]; //cerr<<"Adding to currentHash"<<idToHash[xPoints[0].id]<<endl; visited[points[0].id]=1; for(int i=1;i<n2;i++) { HashToArea[currentHash] += points[i].l - points[i-1].l; int tmp = HashToArea[currentHash]; if(tmp>poleInt) poleInt=tmp; currentId = points[i].id; if(visited[currentId]) { //cerr<<"Adding to currentHash"<<(prime - idToHash[currentId]) % prime<<endl; currentHash = (currentHash + prime - idToHash[currentId]) % prime; } else { //cerr<<"Adding to currentHash"<<(idToHash[currentId])<<endl; currentHash = (currentHash + idToHash[currentId]) % prime; } visited[currentId] = !visited[currentId]; } currentHash=0; HashToArea[currentHash] += L - points[n2-1].l; visited[points[n2-1].id]=0; if(HashToArea[0]>poleInt) poleInt=HashToArea[0]; //cerr<<"HashToArea"<<endl; for (std::map<int,int>::iterator it=HashToArea.begin(); it!=HashToArea.end(); ++it) //cerr << it->first << " => " << it->second << '\n'; //cerr<<"points:"<<endl; for(int i=0;i<n2;i++) //cerr<< points[i].l <<endl; return poleInt; } int main() { ios_base::sync_with_stdio(0); cin>>n>>X>>Y; int currentHash=1; for(int i=0;i<n+1;i++) { idToHash[i]=currentHash; currentHash = (currentHash * 2) % prime; } for(int i = 0;i<=n;i++) { cin >> xPoints[2*i].l >> yPoints[2*i].l >> xPoints[2*i+1].l >> yPoints[2*i+1].l; xPoints[2*i].id=yPoints[2*i].id=xPoints[2*i+1].id=yPoints[2*i+1].id=i; } poleXInt = xD(xPoints,X); //cerr<<"-------------------------------------------------"<<endl; poleYInt = xD(yPoints,Y); poleX = poleXInt; poleY = poleYInt; pole = poleX*poleY; cout<<pole<<endl; 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 | //created by Albert Mosialek #include<bits/stdc++.h> using namespace std; int n,X,Y, currentId; long long poleX, poleY, pole; int poleXInt, poleYInt; struct LabeledPoint{int l; int id;}; LabeledPoint xPoints[1000001]; LabeledPoint yPoints[1000001]; bool visited[1000001]; int idToHash[500001]; map<int, int> HashToArea; const int prime = 982451653; bool LabeledPointComparator( LabeledPoint first, LabeledPoint second) { return first.l < second.l; } int xD(LabeledPoint* points, int L){ HashToArea.clear(); //cerr<<HashToArea[0]<<endl; int poleInt = 0; int n2=2*n; sort(points, points+n2, LabeledPointComparator); int currentHash = 0; HashToArea[currentHash] = points[0].l; currentHash += idToHash[points[0].id]; //cerr<<"Adding to currentHash"<<idToHash[xPoints[0].id]<<endl; visited[points[0].id]=1; for(int i=1;i<n2;i++) { HashToArea[currentHash] += points[i].l - points[i-1].l; int tmp = HashToArea[currentHash]; if(tmp>poleInt) poleInt=tmp; currentId = points[i].id; if(visited[currentId]) { //cerr<<"Adding to currentHash"<<(prime - idToHash[currentId]) % prime<<endl; currentHash = (currentHash + prime - idToHash[currentId]) % prime; } else { //cerr<<"Adding to currentHash"<<(idToHash[currentId])<<endl; currentHash = (currentHash + idToHash[currentId]) % prime; } visited[currentId] = !visited[currentId]; } currentHash=0; HashToArea[currentHash] += L - points[n2-1].l; visited[points[n2-1].id]=0; if(HashToArea[0]>poleInt) poleInt=HashToArea[0]; //cerr<<"HashToArea"<<endl; for (std::map<int,int>::iterator it=HashToArea.begin(); it!=HashToArea.end(); ++it) //cerr << it->first << " => " << it->second << '\n'; //cerr<<"points:"<<endl; for(int i=0;i<n2;i++) //cerr<< points[i].l <<endl; return poleInt; } int main() { ios_base::sync_with_stdio(0); cin>>n>>X>>Y; int currentHash=1; for(int i=0;i<n+1;i++) { idToHash[i]=currentHash; currentHash = (currentHash * 2) % prime; } for(int i = 0;i<=n;i++) { cin >> xPoints[2*i].l >> yPoints[2*i].l >> xPoints[2*i+1].l >> yPoints[2*i+1].l; xPoints[2*i].id=yPoints[2*i].id=xPoints[2*i+1].id=yPoints[2*i+1].id=i; } poleXInt = xD(xPoints,X); //cerr<<"-------------------------------------------------"<<endl; poleYInt = xD(yPoints,Y); poleX = poleXInt; poleY = poleYInt; pole = poleX*poleY; cout<<pole<<endl; return 0; } |