#define _CRT_SECURE_NO_WARNINGS 1 #define _WINSOCK_DEPRECATED_NO_WARNINGS 1 #include <cstdio> #include <algorithm> #include <vector> #include <stack> #include <map> #include <set> #include <unordered_set> using namespace std; struct Pair { int coordinate; int species; }; struct Interval { set<int> species; int score; Interval() { } Interval(int s, int l) { this->species.insert(s); this->score = l; } bool Contains(int needle) { return (species.find(needle) != (species.end())); } }; bool Sorter(Pair const& lhs, Pair const& rhs) { if (lhs.coordinate == rhs.coordinate) { return lhs.species < rhs.species; } return lhs.coordinate < rhs.coordinate; } int findMax(vector<Pair> const& x, int n, int X) { vector<int> cx(n + 1); vector<Interval> stack(n + 13); int stop = 0; Interval start(-1, 0); stack[stop] = start; int c = 0; int maxValue = 0; for(int i = 0; i < x.size(); ++i) { int coordinate = x[i].coordinate; int species = x[i].species; int delta = coordinate - c; stack[stop].score += delta; maxValue = max(maxValue, stack[stop].score); cx[species]++; if (cx[species] == 2) { int si = stop; while (stack[si].Contains(species) == false) { si--; } stack[si].species.erase(species); int diff = stop - si; if (diff > 10) { int maxsi = si; int maxsiCount = 0; for (int j = si; j <= stop; ++j) { if (stack[j].species.size() > maxsiCount) { maxsiCount = stack[j].species.size(); maxsi = j; } } for (int j = si; j <= stop; ++j) { if (j != maxsi) { stack[maxsi].species.insert(stack[j].species.begin(), stack[j].species.end()); stack[j].species = set<int>(); } } stop = si; stack[stop].species.swap(stack[maxsi].species); stack[stop].score = 0; } else { for(int j = si; j<= stop; ++j) { stack[j].score = 0; } } while (stack[stop].species.size() == 0 && stop > 0) { stack[stop].species = set<int>(); stop--; } } else { Interval ns(species, 0); stack[++stop] = ns; } c = coordinate; } int delta = X - c; stack[stop].score += delta; maxValue = max(maxValue, stack[stop].score); return maxValue; } int main() { int n, X, Y; scanf("%d%d%d", &n, &X, &Y); vector<Pair> x(n * 2); vector<Pair> y(n * 2); for (long i = 0; i < n; ++i) { int x1, y1, x2, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2); x[i * 2].species = i + 1; x[i * 2].coordinate = x1; x[i * 2 + 1].species = i + 1; x[i * 2 + 1].coordinate = x2; y[i * 2].species = i + 1; y[i * 2].coordinate = y1; y[i * 2 + 1].species = i + 1; y[i * 2 + 1].coordinate = y2; } std::sort(x.begin(), x.end(), &Sorter); std::sort(y.begin(), y.end(), &Sorter); long long maxX = findMax(x, n, X); long long maxY = findMax(y, n, Y); long long result = maxX * maxY; printf("%lld", 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 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 | #define _CRT_SECURE_NO_WARNINGS 1 #define _WINSOCK_DEPRECATED_NO_WARNINGS 1 #include <cstdio> #include <algorithm> #include <vector> #include <stack> #include <map> #include <set> #include <unordered_set> using namespace std; struct Pair { int coordinate; int species; }; struct Interval { set<int> species; int score; Interval() { } Interval(int s, int l) { this->species.insert(s); this->score = l; } bool Contains(int needle) { return (species.find(needle) != (species.end())); } }; bool Sorter(Pair const& lhs, Pair const& rhs) { if (lhs.coordinate == rhs.coordinate) { return lhs.species < rhs.species; } return lhs.coordinate < rhs.coordinate; } int findMax(vector<Pair> const& x, int n, int X) { vector<int> cx(n + 1); vector<Interval> stack(n + 13); int stop = 0; Interval start(-1, 0); stack[stop] = start; int c = 0; int maxValue = 0; for(int i = 0; i < x.size(); ++i) { int coordinate = x[i].coordinate; int species = x[i].species; int delta = coordinate - c; stack[stop].score += delta; maxValue = max(maxValue, stack[stop].score); cx[species]++; if (cx[species] == 2) { int si = stop; while (stack[si].Contains(species) == false) { si--; } stack[si].species.erase(species); int diff = stop - si; if (diff > 10) { int maxsi = si; int maxsiCount = 0; for (int j = si; j <= stop; ++j) { if (stack[j].species.size() > maxsiCount) { maxsiCount = stack[j].species.size(); maxsi = j; } } for (int j = si; j <= stop; ++j) { if (j != maxsi) { stack[maxsi].species.insert(stack[j].species.begin(), stack[j].species.end()); stack[j].species = set<int>(); } } stop = si; stack[stop].species.swap(stack[maxsi].species); stack[stop].score = 0; } else { for(int j = si; j<= stop; ++j) { stack[j].score = 0; } } while (stack[stop].species.size() == 0 && stop > 0) { stack[stop].species = set<int>(); stop--; } } else { Interval ns(species, 0); stack[++stop] = ns; } c = coordinate; } int delta = X - c; stack[stop].score += delta; maxValue = max(maxValue, stack[stop].score); return maxValue; } int main() { int n, X, Y; scanf("%d%d%d", &n, &X, &Y); vector<Pair> x(n * 2); vector<Pair> y(n * 2); for (long i = 0; i < n; ++i) { int x1, y1, x2, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2); x[i * 2].species = i + 1; x[i * 2].coordinate = x1; x[i * 2 + 1].species = i + 1; x[i * 2 + 1].coordinate = x2; y[i * 2].species = i + 1; y[i * 2].coordinate = y1; y[i * 2 + 1].species = i + 1; y[i * 2 + 1].coordinate = y2; } std::sort(x.begin(), x.end(), &Sorter); std::sort(y.begin(), y.end(), &Sorter); long long maxX = findMax(x, n, X); long long maxY = findMax(y, n, Y); long long result = maxX * maxY; printf("%lld", result); } |