#include<cstdio> #include<algorithm> #include<map> using namespace std; static int n; struct punkt { int x; int in; bool pocz; bool operator<(punkt a) const{ if(x == a.x) return pocz; return x < a.x; } }; static punkt tab1[1000000]; static punkt tab2[1000000]; typedef unsigned long long ull; static ull hash1 = 0; static ull hash2 = 0; static const ull M1 = 3679260821; static const ull g1 = 37; static const ull M2 = 4226801521; static const ull g2 = 13; static ull getHash(){ return (hash1 << 32) | hash2; } static unsigned int powerMod(unsigned int g, unsigned int n, ull M){ unsigned long long tmp = g, res = 1; while(n){ if(n & 1) res = (res * tmp) % M; tmp = (tmp * tmp) % M; n >>= 1; } return (unsigned int) res; } static void updateHashes(unsigned int pos, bool bit){ unsigned int G1 = powerMod((unsigned int) g1, pos, M1); unsigned int G2 = powerMod((unsigned int) g2, pos, M2); if(bit){ hash1 = (hash1 + G1) % M1; hash2 = (hash2 + G2) % M2; } else{ hash1 = (hash1 + M1 - G1) % M1; hash2 = (hash2 + M2 - G2) % M2; } } static ull wynik(punkt* tab, int maxX){ map<ull, int> mapa; int pop = 0; for(int i = 0; i < n; ++i){ int x = tab[i].x; bool pocz = tab[i].pocz; int in = tab[i].in; if(x != pop){ ull hasz = getHash(); if(mapa.find(hasz) == mapa.end()){ mapa[hasz] = x - pop; } else{ mapa[hasz] = mapa[hasz] + x - pop; } } updateHashes(in, pocz); pop = x; } ull hasz = getHash(); mapa[hasz] = mapa[hasz] + maxX - pop; int maxi = 0; for(map<ull, int>::iterator it = mapa.begin(); it != mapa.end(); ++it ){ if (it ->second > maxi) { maxi = it->second; } } mapa.clear(); return maxi; } int main(){ int X, Y; scanf("%i%i%i", &n, &X, &Y); for(int i = 0; i < n; ++i){ int x1, y1, x2, y2; scanf("%i%i%i%i", &x1, &y1, &x2, &y2); if(x1 > x2) swap(x1, x2); if(y1 > y2) swap(y1, y2); tab1[2 * i].pocz = true; tab1[2 * i].in = i; tab1[2 * i].x = x1; tab1[2 * i + 1].pocz = false; tab1[2 * i + 1].in = i; tab1[2 * i + 1].x = x2; tab2[2 * i].pocz = true; tab2[2 * i].in = i; tab2[2 * i].x = y1; tab2[2 * i + 1].pocz = false; tab2[2 * i + 1].in = i; tab2[2 * i + 1].x = y2; } n *= 2; sort(tab1, tab1 + n); sort(tab2, tab2 + n); printf("%llu\n", wynik(tab1, X) * wynik(tab2, Y)); }
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 | #include<cstdio> #include<algorithm> #include<map> using namespace std; static int n; struct punkt { int x; int in; bool pocz; bool operator<(punkt a) const{ if(x == a.x) return pocz; return x < a.x; } }; static punkt tab1[1000000]; static punkt tab2[1000000]; typedef unsigned long long ull; static ull hash1 = 0; static ull hash2 = 0; static const ull M1 = 3679260821; static const ull g1 = 37; static const ull M2 = 4226801521; static const ull g2 = 13; static ull getHash(){ return (hash1 << 32) | hash2; } static unsigned int powerMod(unsigned int g, unsigned int n, ull M){ unsigned long long tmp = g, res = 1; while(n){ if(n & 1) res = (res * tmp) % M; tmp = (tmp * tmp) % M; n >>= 1; } return (unsigned int) res; } static void updateHashes(unsigned int pos, bool bit){ unsigned int G1 = powerMod((unsigned int) g1, pos, M1); unsigned int G2 = powerMod((unsigned int) g2, pos, M2); if(bit){ hash1 = (hash1 + G1) % M1; hash2 = (hash2 + G2) % M2; } else{ hash1 = (hash1 + M1 - G1) % M1; hash2 = (hash2 + M2 - G2) % M2; } } static ull wynik(punkt* tab, int maxX){ map<ull, int> mapa; int pop = 0; for(int i = 0; i < n; ++i){ int x = tab[i].x; bool pocz = tab[i].pocz; int in = tab[i].in; if(x != pop){ ull hasz = getHash(); if(mapa.find(hasz) == mapa.end()){ mapa[hasz] = x - pop; } else{ mapa[hasz] = mapa[hasz] + x - pop; } } updateHashes(in, pocz); pop = x; } ull hasz = getHash(); mapa[hasz] = mapa[hasz] + maxX - pop; int maxi = 0; for(map<ull, int>::iterator it = mapa.begin(); it != mapa.end(); ++it ){ if (it ->second > maxi) { maxi = it->second; } } mapa.clear(); return maxi; } int main(){ int X, Y; scanf("%i%i%i", &n, &X, &Y); for(int i = 0; i < n; ++i){ int x1, y1, x2, y2; scanf("%i%i%i%i", &x1, &y1, &x2, &y2); if(x1 > x2) swap(x1, x2); if(y1 > y2) swap(y1, y2); tab1[2 * i].pocz = true; tab1[2 * i].in = i; tab1[2 * i].x = x1; tab1[2 * i + 1].pocz = false; tab1[2 * i + 1].in = i; tab1[2 * i + 1].x = x2; tab2[2 * i].pocz = true; tab2[2 * i].in = i; tab2[2 * i].x = y1; tab2[2 * i + 1].pocz = false; tab2[2 * i + 1].in = i; tab2[2 * i + 1].x = y2; } n *= 2; sort(tab1, tab1 + n); sort(tab2, tab2 + n); printf("%llu\n", wynik(tab1, X) * wynik(tab2, Y)); } |