#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_5_A" #include <algorithm> #include <iostream> #include "Mylib/Algorithm/imos_1d.cpp" #include "Mylib/IO/input_tuples.cpp" namespace hl = haar_lib; int main() { int N, T; std::cin >> N >> T; hl::imos_1d<int> imos(T + 1); for (auto [l, r] : hl::input_tuples<int, int>(N)) { imos.update(l, r, 1); } const auto res = imos.build(); int ans = *std::max_element(res.begin(), res.end()); std::cout << ans << std::endl; return 0; }
#line 1 "test/aoj/DSL_5_A/main.test.cpp" #define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_5_A" #include <algorithm> #include <iostream> #line 2 "Mylib/Algorithm/imos_1d.cpp" #include <cassert> #include <vector> namespace haar_lib { template <typename T> struct imos_1d { using value_type = T; private: std::vector<T> data_; int n_; public: imos_1d() {} imos_1d(int n) : data_(n), n_(n) {} void update(int l, int r, T val) { // [l, r) assert(0 <= l and l <= r and r <= n_); data_[l] += val; if (r < n_) data_[r] -= val; } auto build() const { std::vector<T> ret(data_); for (int i = 1; i < n_; ++i) { ret[i] += ret[i - 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_A/main.test.cpp" namespace hl = haar_lib; int main() { int N, T; std::cin >> N >> T; hl::imos_1d<int> imos(T + 1); for (auto [l, r] : hl::input_tuples<int, int>(N)) { imos.update(l, r, 1); } const auto res = imos.build(); int ans = *std::max_element(res.begin(), res.end()); std::cout << ans << std::endl; return 0; }