#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_5_B" #include <algorithm> #include <iostream> #include "Mylib/Algorithm/imos_2d.cpp" #include "Mylib/IO/input_tuples.cpp" namespace hl = haar_lib; int main() { int N; std::cin >> N; hl::imos_2d<int> imos(1000, 1000); for (auto [x1, y1, x2, y2] : hl::input_tuples<int, int, int, int>(N)) { imos.update({x1, y1}, {x2, y2}, 1); } const auto res = imos.build(); int ans = 0; for (auto &v : res) { ans = std::max(ans, *std::max_element(v.begin(), v.end())); } std::cout << ans << std::endl; return 0; }
#line 1 "test/aoj/DSL_5_B/main.test.cpp" #define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_5_B" #include <algorithm> #include <iostream> #line 2 "Mylib/Algorithm/imos_2d.cpp" #include <cassert> #include <vector> namespace haar_lib { template <typename T> struct imos_2d { using value_type = T; private: std::vector<std::vector<T>> data_; int n_, m_; public: imos_2d() {} imos_2d(int n, int m) : data_(n, std::vector<T>(m)), n_(n), m_(m) {} void update(std::pair<int, int> p1, std::pair<int, int> p2, T val) { const auto [x1, y1] = p1; const auto [x2, y2] = p2; assert(0 <= x1 and x1 <= x2 and x2 <= n_); assert(0 <= y1 and y1 <= y2 and y2 <= m_); data_[x1][y1] += val; if (x2 < n_ and y2 < m_) data_[x2][y2] += val; if (y2 < m_) data_[x1][y2] -= val; if (x2 < n_) data_[x2][y1] -= val; } auto build() const { std::vector<std::vector<T>> ret(data_); for (int i = 1; i < n_; ++i) { for (int j = 0; j < m_; ++j) { ret[i][j] += ret[i - 1][j]; } } for (int i = 0; i < n_; ++i) { for (int j = 1; j < m_; ++j) { ret[i][j] += ret[i][j - 1]; } } return ret; } }; } // namespace haar_lib #line 2 "Mylib/IO/input_tuples.cpp" #include <initializer_list> #line 4 "Mylib/IO/input_tuples.cpp" #include <tuple> #include <utility> #line 6 "Mylib/IO/input_tuple.cpp" namespace haar_lib { template <typename T, size_t... I> static void input_tuple_helper(std::istream &s, T &val, std::index_sequence<I...>) { (void) std::initializer_list<int>{(void(s >> std::get<I>(val)), 0)...}; } template <typename T, typename U> std::istream &operator>>(std::istream &s, std::pair<T, U> &value) { s >> value.first >> value.second; return s; } template <typename... Args> std::istream &operator>>(std::istream &s, std::tuple<Args...> &value) { input_tuple_helper(s, value, std::make_index_sequence<sizeof...(Args)>()); return s; } } // namespace haar_lib #line 8 "Mylib/IO/input_tuples.cpp" namespace haar_lib { template <typename... Args> class InputTuples { struct iter { using value_type = std::tuple<Args...>; value_type value; bool fetched = false; int N, c = 0; value_type operator*() { if (not fetched) { std::cin >> value; } return value; } void operator++() { ++c; fetched = false; } bool operator!=(iter &) const { return c < N; } iter(int N) : N(N) {} }; int N; public: InputTuples(int N) : N(N) {} iter begin() const { return iter(N); } iter end() const { return iter(N); } }; template <typename... Args> auto input_tuples(int N) { return InputTuples<Args...>(N); } } // namespace haar_lib #line 7 "test/aoj/DSL_5_B/main.test.cpp" namespace hl = haar_lib; int main() { int N; std::cin >> N; hl::imos_2d<int> imos(1000, 1000); for (auto [x1, y1, x2, y2] : hl::input_tuples<int, int, int, int>(N)) { imos.update({x1, y1}, {x2, y2}, 1); } const auto res = imos.build(); int ans = 0; for (auto &v : res) { ans = std::max(ans, *std::max_element(v.begin(), v.end())); } std::cout << ans << std::endl; return 0; }