#include <set> #include <vector> #include <iostream> #include <algorithm> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair<int,int>; using pll = pair<ll,ll>; using vi = vector<int>; using vb = vector<bool>; using vc = vector<char>; using vvc = vector<vc>; using vvi = vector<vi>; using vvb = vector<vb>; using vpii = vector<pii>; using vpll = vector<pll>; using vll = vector<ll>; using vvll = vector<vll>; using vull = vector<ull>; #define f first #define s second #define pb emplace_back #define graph vector<vertex> #define rep(i, begin, end) for(__typeof(end) i = (begin); i <= (end); ++i) #define repr(i, begin, end) for(__typeof(end) i = (begin); i >= (end); --i) #define bend(X) X.begin(), X.end() #define print cout<< #ifdef LOCAL #define nl << endl #define deb(x) cout << #x << " = " << x << endl #define say(x) cout << x << endl #else #define nl << '\n' #define deb(x) #define say(x) #endif template <ll mod> struct nu { nu(ll val = 0) : v{val} { if(v>=mod || v <= -mod) v %= mod; if(v < 0) v += mod; }; ll v; operator ll() {return v;}; nu<mod> operator+(const nu<mod>& o) const {return {v+o.v};}; nu<mod> operator-(const nu<mod>& o) const {return {v-o.v};}; nu<mod> operator*(const nu<mod>& o) const {return {v*o.v};}; nu<mod> operator+=(const nu<mod>& o) {v = nu<mod> {v+o.v}; return *this;}; nu<mod> operator-=(const nu<mod>& o) {v = nu<mod> {v-o.v}; return *this;}; nu<mod> operator*=(const nu<mod>& o) {v = nu<mod> {v*o.v}; return *this;}; nu<mod> operator!() const { nu<mod> R = 1; rep(i, 2, (ll)v) R *= nu<mod>{i}; return R; } nu<mod> operator^(ll b) const { nu<mod> R{1}, a{v}; while(b > 0) { if(b&1) R *= a; a *= a, b /= 2; } return R; } nu<mod> operator/(const nu<mod>& o) const { return (*this)*(o^(mod-2)); } nu<mod> operator/=(const nu<mod>& o) { v = ll((*this)/o); return *this; } }; constexpr int INF = 2000000000; constexpr ll INFl = 2000000000ll; constexpr ll INFll = 2000000000000000000ll; constexpr ll mod = 1e9+7; using num = nu<mod>; template <typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2> x) { os << x.f << ' ' << x.s; return os; } template <typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& x) { is >> x.f >> x.s; return is; } template <typename T> ostream& operator<<(ostream& os, vector<T>& x) { for(T& i : x) os << i << ' '; return os; } template <typename T> istream& operator>>(istream& is, vector<T>& x) { for(T& i : x) is >> i; return is; } template <typename T1, typename T2> pair<T1,T2> operator+(const pair<T1,T2>& A, const pair<T1,T2>& B) { return {A.f+B.f, A.s+B.s}; } template <typename T1, typename T2> pair<T1,T2> operator-(const pair<T1,T2>& A, const pair<T1,T2>& B) { return {A.f-B.f, A.s-B.s}; } template <typename T1, typename T2> pair<T1,T2> operator-(const pair<T1,T2>& A) { return {-A.f, -A.s}; } template<typename T1, typename T2> bool maxe(T1& A, const T2& B) {if(B>A){A=B;return 1;}return 0;} template<typename T1, typename T2> bool mine(T1& A, const T2& B) {if(B<A){A=B;return 1;}return 0;} // // END OF DEFINES // struct node { node(int l = 0, int r = 0) : l{l}, r{r} {}; node* L = nullptr; node* R = nullptr; int l, r; ll val = 0; ll sum = 0; }; struct tree { node* root = nullptr; inline void reset(int n) { root = new node(0, n-1); } void _add(node* v, int L, int R, int val) { if(R < v->l || v->r < L) return; else if(L <= v->l && v->r <= R) v->val += val; else { int m = (v->l+v->r)/2; if(v->L == nullptr) v->L = new node(v->l, m); if(v->R == nullptr) v->R = new node(m+1, v->r); _add(v->L, L, R, val); _add(v->R, L, R, val); } calcSum(v); } inline void calcSum(node* v) { if(v->val > 0) { v->sum = 0; return; } v->sum = 0; int m = (v->l+v->r)/2; if(v->L == nullptr) v->sum += m-v->l+1; else v->sum += v->L->sum; if(v->R == nullptr) v->sum += v->r-m; else v->sum += v->R->sum; } inline void add(int L, int R, int val) { if(L <= R) _add(root, L, R, val); } inline void addZew(int L, int R, int val) { add(root->l, L-1, val); add(R+1, root->r, val); } inline ll count() { return root->sum; } }; struct rec { rec(int a = 0, int b = 0, int c = 0, int d = 0) : b{a, c}, e{b, d} {}; int b[2], e[2]; }; constexpr int N = 500000; int n, m[2]; rec recs[N]; pii B[N], E[N]; tree T; bool in() { cin >> n >> m[0] >> m[1]; rep(i, 0, n-1) { int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2; recs[i] = rec(min(x1, x2), (max(x1,x2))-1, min(y1, y2), max(y1, y2)-1); } return true; } ll policzOs(int k) { T.reset(m[k]); set<int> points; points.insert(0); points.insert(m[k]-1); rep(i, 0, n-1) { points.insert(recs[i].b[k]); points.insert(recs[i].e[k]+1); B[i] = {recs[i].b[k], i}, E[i] = {recs[i].e[k], i}; T.add(recs[i].b[k], recs[i].e[k], 1); } sort(B, B+n); sort(E, E+n); int b = 0, e = 0; ll R = 0; for(auto i : points) { while(b < n && B[b].f <= i) { int x = recs[B[b].s].b[k]; int y = recs[B[b].s].e[k]; T.add(x, y, -1); T.addZew(x, y, 1); ++b; } while(e < n && E[e].f < i) { int x = recs[E[e].s].b[k]; int y = recs[E[e].s].e[k]; T.addZew(x, y, -1); T.add(x, y, 1); ++e; } maxe(R, T.count()); } return R; } ll solve() { return policzOs(0)*policzOs(1); return -INF; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int noOfTests = 1; //cin >> noOfTests; while(noOfTests --> 0) { if(!in()) { cout << "popsute_wejscie\n"; continue; } ll result = solve(); if(result == ll(-'t')) cout << "TAK\n"; else if(result == ll(-'n')) cout << "NIE\n"; else if(result == ll(-'e')) cout << "Popsute\n"; else if(result != -INF) cout << result << '\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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | #include <set> #include <vector> #include <iostream> #include <algorithm> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair<int,int>; using pll = pair<ll,ll>; using vi = vector<int>; using vb = vector<bool>; using vc = vector<char>; using vvc = vector<vc>; using vvi = vector<vi>; using vvb = vector<vb>; using vpii = vector<pii>; using vpll = vector<pll>; using vll = vector<ll>; using vvll = vector<vll>; using vull = vector<ull>; #define f first #define s second #define pb emplace_back #define graph vector<vertex> #define rep(i, begin, end) for(__typeof(end) i = (begin); i <= (end); ++i) #define repr(i, begin, end) for(__typeof(end) i = (begin); i >= (end); --i) #define bend(X) X.begin(), X.end() #define print cout<< #ifdef LOCAL #define nl << endl #define deb(x) cout << #x << " = " << x << endl #define say(x) cout << x << endl #else #define nl << '\n' #define deb(x) #define say(x) #endif template <ll mod> struct nu { nu(ll val = 0) : v{val} { if(v>=mod || v <= -mod) v %= mod; if(v < 0) v += mod; }; ll v; operator ll() {return v;}; nu<mod> operator+(const nu<mod>& o) const {return {v+o.v};}; nu<mod> operator-(const nu<mod>& o) const {return {v-o.v};}; nu<mod> operator*(const nu<mod>& o) const {return {v*o.v};}; nu<mod> operator+=(const nu<mod>& o) {v = nu<mod> {v+o.v}; return *this;}; nu<mod> operator-=(const nu<mod>& o) {v = nu<mod> {v-o.v}; return *this;}; nu<mod> operator*=(const nu<mod>& o) {v = nu<mod> {v*o.v}; return *this;}; nu<mod> operator!() const { nu<mod> R = 1; rep(i, 2, (ll)v) R *= nu<mod>{i}; return R; } nu<mod> operator^(ll b) const { nu<mod> R{1}, a{v}; while(b > 0) { if(b&1) R *= a; a *= a, b /= 2; } return R; } nu<mod> operator/(const nu<mod>& o) const { return (*this)*(o^(mod-2)); } nu<mod> operator/=(const nu<mod>& o) { v = ll((*this)/o); return *this; } }; constexpr int INF = 2000000000; constexpr ll INFl = 2000000000ll; constexpr ll INFll = 2000000000000000000ll; constexpr ll mod = 1e9+7; using num = nu<mod>; template <typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2> x) { os << x.f << ' ' << x.s; return os; } template <typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& x) { is >> x.f >> x.s; return is; } template <typename T> ostream& operator<<(ostream& os, vector<T>& x) { for(T& i : x) os << i << ' '; return os; } template <typename T> istream& operator>>(istream& is, vector<T>& x) { for(T& i : x) is >> i; return is; } template <typename T1, typename T2> pair<T1,T2> operator+(const pair<T1,T2>& A, const pair<T1,T2>& B) { return {A.f+B.f, A.s+B.s}; } template <typename T1, typename T2> pair<T1,T2> operator-(const pair<T1,T2>& A, const pair<T1,T2>& B) { return {A.f-B.f, A.s-B.s}; } template <typename T1, typename T2> pair<T1,T2> operator-(const pair<T1,T2>& A) { return {-A.f, -A.s}; } template<typename T1, typename T2> bool maxe(T1& A, const T2& B) {if(B>A){A=B;return 1;}return 0;} template<typename T1, typename T2> bool mine(T1& A, const T2& B) {if(B<A){A=B;return 1;}return 0;} // // END OF DEFINES // struct node { node(int l = 0, int r = 0) : l{l}, r{r} {}; node* L = nullptr; node* R = nullptr; int l, r; ll val = 0; ll sum = 0; }; struct tree { node* root = nullptr; inline void reset(int n) { root = new node(0, n-1); } void _add(node* v, int L, int R, int val) { if(R < v->l || v->r < L) return; else if(L <= v->l && v->r <= R) v->val += val; else { int m = (v->l+v->r)/2; if(v->L == nullptr) v->L = new node(v->l, m); if(v->R == nullptr) v->R = new node(m+1, v->r); _add(v->L, L, R, val); _add(v->R, L, R, val); } calcSum(v); } inline void calcSum(node* v) { if(v->val > 0) { v->sum = 0; return; } v->sum = 0; int m = (v->l+v->r)/2; if(v->L == nullptr) v->sum += m-v->l+1; else v->sum += v->L->sum; if(v->R == nullptr) v->sum += v->r-m; else v->sum += v->R->sum; } inline void add(int L, int R, int val) { if(L <= R) _add(root, L, R, val); } inline void addZew(int L, int R, int val) { add(root->l, L-1, val); add(R+1, root->r, val); } inline ll count() { return root->sum; } }; struct rec { rec(int a = 0, int b = 0, int c = 0, int d = 0) : b{a, c}, e{b, d} {}; int b[2], e[2]; }; constexpr int N = 500000; int n, m[2]; rec recs[N]; pii B[N], E[N]; tree T; bool in() { cin >> n >> m[0] >> m[1]; rep(i, 0, n-1) { int x1, x2, y1, y2; cin >> x1 >> y1 >> x2 >> y2; recs[i] = rec(min(x1, x2), (max(x1,x2))-1, min(y1, y2), max(y1, y2)-1); } return true; } ll policzOs(int k) { T.reset(m[k]); set<int> points; points.insert(0); points.insert(m[k]-1); rep(i, 0, n-1) { points.insert(recs[i].b[k]); points.insert(recs[i].e[k]+1); B[i] = {recs[i].b[k], i}, E[i] = {recs[i].e[k], i}; T.add(recs[i].b[k], recs[i].e[k], 1); } sort(B, B+n); sort(E, E+n); int b = 0, e = 0; ll R = 0; for(auto i : points) { while(b < n && B[b].f <= i) { int x = recs[B[b].s].b[k]; int y = recs[B[b].s].e[k]; T.add(x, y, -1); T.addZew(x, y, 1); ++b; } while(e < n && E[e].f < i) { int x = recs[E[e].s].b[k]; int y = recs[E[e].s].e[k]; T.addZew(x, y, -1); T.add(x, y, 1); ++e; } maxe(R, T.count()); } return R; } ll solve() { return policzOs(0)*policzOs(1); return -INF; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int noOfTests = 1; //cin >> noOfTests; while(noOfTests --> 0) { if(!in()) { cout << "popsute_wejscie\n"; continue; } ll result = solve(); if(result == ll(-'t')) cout << "TAK\n"; else if(result == ll(-'n')) cout << "NIE\n"; else if(result == ll(-'e')) cout << "Popsute\n"; else if(result != -INF) cout << result << '\n'; } return 0; } |