結果
問題 | No.674 n連勤 |
ユーザー | shiomusubi496 |
提出日時 | 2022-02-15 18:36:53 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 87 ms / 2,000 ms |
コード長 | 13,230 bytes |
コンパイル時間 | 2,329 ms |
コンパイル使用メモリ | 212,388 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-29 07:07:27 |
合計ジャッジ時間 | 4,082 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 8 ms
5,376 KB |
testcase_12 | AC | 8 ms
5,376 KB |
testcase_13 | AC | 69 ms
5,376 KB |
testcase_14 | AC | 79 ms
5,376 KB |
testcase_15 | AC | 69 ms
5,376 KB |
testcase_16 | AC | 87 ms
5,376 KB |
testcase_17 | AC | 87 ms
5,376 KB |
testcase_18 | AC | 77 ms
5,376 KB |
testcase_19 | AC | 74 ms
5,376 KB |
ソースコード
#line 1 "test/yuki/1601.test.cpp" #define PROBLEM "https://yukicoder.me/problems/1601" #line 2 "other/template.hpp" #include<bits/stdc++.h> #ifndef __COUNTER__ #define __COUNTER__ __LINE__ #endif #define REP_SELECTER(a, b, c, d, e, ...) e #define REP1_0(b, c) REP1_1(b, c) #define REP1_1(b, c) for (ll REP_COUNTER_ ## c = 0; REP_COUNTER_ ## c < (ll)(b); ++ REP_COUNTER_ ## c) #define REP1(b) REP1_0(b, __COUNTER__) #define REP2(i, b) for (ll i = 0; i < (ll)(b); ++i) #define REP3(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i) #define REP4(i, a, b, c) for (ll i = (ll)(a); i < (ll)(b); i += (ll)(c)) #define rep(...) REP_SELECTER(__VA_ARGS__, REP4, REP3, REP2, REP1) (__VA_ARGS__) #define RREP2(i, a) for (ll i = (ll)(a) - 1; i >= 0; --i) #define RREP3(i, a, b) for (ll i = (ll)(a) - 1; i >= (ll)(b); --i) #define RREP4(i, a, b, c) for (ll i = (ll)(a) - 1; i >= (ll)(b); i -= (ll)(c)) #define rrep(...) REP_SELECTER(__VA_ARGS__, RREP4, RREP3, RREP2) (__VA_ARGS__) #define REPS2(i, b) for (ll i = 1; i <= (ll)(b); ++i) #define REPS3(i, a, b) for (ll i = (ll)(a) + 1; i <= (ll)(b); ++i) #define REPS4(i, a, b, c) for (ll i = (ll)(a) + 1; i <= (ll)(b); i += (ll)(c)) #define reps(...) REP_SELECTER(__VA_ARGS__, REPS4, REPS3, REPS2) (__VA_ARGS__) #define RREPS2(i, a) for (ll i = (ll)(a); i > 0; --i) #define RREPS3(i, a, b) for (ll i = (ll)(a); i > (ll)(b); --i) #define RREPS4(i, a, b, c) for (ll i = (ll)(a); i > (ll)(b); i -= (ll)(c)) #define rreps(...) REP_SELECTER(__VA_ARGS__, RREPS4, RREPS3, RREPS2) (__VA_ARGS__) #define each_for(...) for (auto&& __VA_ARGS__) #define each_const(...) for (const auto& __VA_ARGS__) #define all(v) std::begin(v), std::end(v) #define rall(v) std::rbegin(v), std::rend(v) #if __cplusplus >= 201402L #define CONSTEXPR constexpr #else #define CONSTEXPR #endif #ifdef __cpp_if_constexpr #define IF_CONSTEXPR constexpr #else #define IF_CONSTEXPR #endif using ll = long long; using ull = unsigned long long; using ld = long double; using PLL = std::pair<ll, ll>; template<class T> using prique = std::priority_queue<T, std::vector<T>, std::greater<T>>; template<class T> class infinity { public: static constexpr T value = std::numeric_limits<T>::max() / 2; static constexpr T mvalue = std::numeric_limits<T>::min() / 2; static constexpr T max = std::numeric_limits<T>::max(); static constexpr T min = std::numeric_limits<T>::min(); }; #if __cplusplus <= 201402L template<class T> constexpr T infinity<T>::value; template<class T> constexpr T infinity<T>::mvalue; template<class T> constexpr T infinity<T>::max; template<class T> constexpr T infinity<T>::min; #endif #if __cplusplus >= 201402L template<class T> constexpr T INF = infinity<T>::value; #endif constexpr ll inf = infinity<ll>::value; constexpr ld EPS = 1e-8; constexpr ld PI = 3.1415926535897932384626; template<class T, class U> std::ostream& operator<<(std::ostream& ost, const std::pair<T, U>& p) { return ost << p.first << ' ' << p.second; } template<class T, class U> std::istream& operator>>(std::istream& ist, std::pair<T, U>& p) { return ist >> p.first >> p.second; } template<class Container, typename std::enable_if<!std::is_same<Container, std::string>::value>::type* = nullptr> auto operator<<(std::ostream& ost, const Container& cont) -> decltype(cont.begin(), cont.end(), ost) { for (auto itr = cont.begin(); itr != cont.end(); ++itr) { if (itr != cont.begin()) ost << ' '; ost << *itr; } return ost; } template<class Container, typename std::enable_if<!std::is_same<Container, std::string>::value>::type* = nullptr> auto operator>>(std::istream& ist, Container& cont) -> decltype(cont.begin(), cont.end(), ist) { for (auto itr = cont.begin(); itr != cont.end(); ++itr) ist >> *itr; return ist; } template<class T, class U> inline constexpr bool chmin(T &a, const U &b) noexcept { return a > b ? a = b, true : false; } template<class T, class U> inline constexpr bool chmax(T &a, const U &b) noexcept { return a < b ? a = b, true : false; } inline CONSTEXPR ll gcd(ll a, ll b) noexcept { while (b) { const ll c = a; a = b; b = c % b; } return a; } inline CONSTEXPR ll lcm(ll a, ll b) noexcept { return a / gcd(a, b) * b; } inline CONSTEXPR bool is_prime(ll N) noexcept { if (N <= 1) return false; for (ll i = 2; i * i <= N; ++i) { if (N % i == 0) return false; } return true; } inline std::vector<ll> prime_factor(ll N) noexcept { std::vector<ll> res; for (ll i = 2; i * i <= N; ++i) { while (N % i == 0) { res.push_back(i); N /= i; } } if (N != 1) res.push_back(N); return res; } inline CONSTEXPR ll my_pow(ll a, ll b) noexcept { ll res = 1; while (b) { if (b & 1) res *= a; b >>= 1; a *= a; } return res; } inline CONSTEXPR ll mod_pow(ll a, ll b, ll mod) noexcept { a %= mod; ll res = 1; while (b) { if (b & 1) (res *= a) %= mod; b >>= 1; (a *= a) %= mod; } return res; } PLL extGCD(ll a, ll b) noexcept { if (b == 0) return PLL{1, 0}; PLL p = extGCD(b, a % b); std::swap(p.first, p.second); p.second -= p.first * (a / b); if (p.first < 0) { p.first += b; p.second -= a; } return p; } ll mod_inv(ll a, ll mod) noexcept { const PLL p = extGCD(a, mod); assert(p.first * a + p.second * mod == 1); return p.first; } PLL ChineseRemainder(ll b1, ll m1, ll b2, ll m2) noexcept { const PLL p = extGCD(m1, m2); const ll g = p.first * m1 + p.second * m2; const ll l = m1 / g * m2; if ((b2 - b1) % g != 0) return PLL{-1, -1}; const ll x = (b2 - b1) / g * p.first % (m2 / g); return {(x * m1 + b1 + l) % l, l}; } PLL ChineseRemainders(const std::vector<ll>& b, const std::vector<ll>& m) noexcept { PLL res{0, 1}; rep (i, b.size()) { res = ChineseRemainder(res.first, res.second, b[i], m[i]); if (res.first == -1) return res; } return res; } template<class F> class RecLambda { private: F f; public: explicit constexpr RecLambda(F&& f_) : f(std::forward<F>(f_)) {} template<class... Args> constexpr auto operator()(Args&&... args) const -> decltype(f(*this, std::forward<Args>(args)...)) { return f(*this, std::forward<Args>(args)...); } }; template<class F> inline constexpr RecLambda<F> rec_lambda(F&& f) { return RecLambda<F>(std::forward<F>(f)); } template<class Head, class... Tails> struct multi_dim_vector { using type = std::vector<typename multi_dim_vector<Tails...>::type>; }; template<class T> struct multi_dim_vector<T> { using type = T; }; template<class T, class Arg> constexpr std::vector<T> make_vec(int n, Arg&& arg) { return std::vector<T>(n, std::forward<Arg>(arg)); } template<class T, class... Args> constexpr typename multi_dim_vector<Args..., T>::type make_vec(int n, Args&&... args) { return typename multi_dim_vector<Args..., T>::type (n, make_vec<T>(std::forward<Args>(args)...)); } inline CONSTEXPR int popcnt(ull x) { #if __cplusplus >= 202002L return std::popcount(x); #endif x = (x & 0x5555555555555555) + ((x >> 1 ) & 0x5555555555555555); x = (x & 0x3333333333333333) + ((x >> 2 ) & 0x3333333333333333); x = (x & 0x0f0f0f0f0f0f0f0f) + ((x >> 4 ) & 0x0f0f0f0f0f0f0f0f); x = (x & 0x00ff00ff00ff00ff) + ((x >> 8 ) & 0x00ff00ff00ff00ff); x = (x & 0x0000ffff0000ffff) + ((x >> 16) & 0x0000ffff0000ffff); return (x & 0x00000000ffffffff) + ((x >> 32) & 0x00000000ffffffff); } template<class T> class presser { private: std::vector<T> dat; bool sorted = false; public: presser() = default; presser(const std::vector<T>& vec) : dat(vec) {} presser(std::vector<T>&& vec) : dat(std::move(vec)) {} presser(std::initializer_list<T> il) : dat(il.begin(), il.end()) {} void reserve(int n) { assert(!sorted); dat.reserve(n); } void push_back(const T& v) { assert(!sorted); dat.push_back(v); } void push_back(T&& v) { assert(!sorted); dat.push_back(std::move(v)); } void push(const std::vector<T>& vec) { assert(!sorted); dat.reserve(dat.size() + vec.size()); std::copy(all(vec), std::back_inserter(dat)); } int build() { assert(!sorted); sorted = true; std::sort(all(dat)); dat.erase(std::unique(all(dat)), dat.end()); return dat.size(); } const T& operator[](int k) const& { assert(sorted); assert(0 <= k && k < (int)dat.size()); return dat[k]; } T operator[](int k) && { assert(sorted); assert(0 <= k && k < (int)dat.size()); return std::move(dat[k]); } int get_index(const T& val) const { assert(sorted); return static_cast<int>(std::lower_bound(all(dat), val) - dat.begin()); } std::vector<int> pressed(const std::vector<T>& vec) const { assert(sorted); std::vector<int> res(vec.size()); rep (i, vec.size()) res[i] = get_index(vec[i]); return res; } void press(std::vector<T>& vec) const { assert(sorted); static_assert(std::is_integral<T>::value, "cannot convert from int type"); rep (i, vec.size()) vec[i] = get_index(vec[i]); } int size() const { assert(sorted); return dat.size(); } const std::vector<T>& data() const& { return dat; } std::vector<T> data() && { return std::move(dat); } }; #line 2 "data-struct/other/RangeSet.hpp" #line 4 "data-struct/other/RangeSet.hpp" class RangeSet { protected: int sz; std::set<std::pair<ll, ll>> st; typename std::set<std::pair<ll, ll>>::iterator st_emplace_hint(const typename std::set<std::pair<ll, ll>>::iterator& itr, ll l, ll r) { sz += r - l; return st.emplace_hint(itr, l, r); } typename std::set<std::pair<ll, ll>>::iterator st_erase(const typename std::set<std::pair<ll, ll>>::iterator& itr) { sz -= itr->second - itr->first; return st.erase(itr); } public: RangeSet() : sz(0) {} RangeSet(const std::set<std::pair<ll, ll>>& st_) : sz(0) { each_const (p : st_) insert(p.first, p.second); } bool empty() const { return st.empty(); } int size() const { return st.size(); } ll length() const { return sz; } const std::set<std::pair<ll, ll>>& get_data() const& { return st; } std::set<std::pair<ll, ll>>& get_data() & { return st; } std::set<std::pair<ll, ll>> get_data() && { return std::move(st); } auto insert(ll l, ll r) -> decltype(st.insert({l, r})) { assert(l <= r); if (l == r) return {st.end(), false}; auto itr = st.lower_bound({l, r}); if (itr != st.end() && itr->first == l) return {itr, false}; if (itr != st.begin() && prev(itr)->first != l && r <= prev(itr)->second) { return {prev(itr), false}; } sz += r - l; itr = st_emplace_hint(itr, l, r); while (itr != prev(st.end()) && next(itr)->first <= itr->second) { if (next(itr)->second <= itr->second) st_erase(next(itr)); else { itr = st_emplace_hint(next(itr), itr->first, next(itr)->second); st_erase(prev(itr)); st_erase(next(itr)); } } while (itr != st.begin() && itr->first <= prev(itr)->second) { if (itr->first == prev(itr)->first) st_erase(prev(itr)); else { itr = st_emplace_hint(itr, prev(itr)->first, itr->second); st_erase(prev(itr)); st_erase(next(itr)); } } return {itr, true}; } auto insert(ll l) -> decltype(insert(l, l + 1)) { return insert(l, l + 1); } void erase(ll l, ll r) { assert(l <= r); if (l == r) return; auto itr = st.lower_bound({l, r}); while (itr != st.end() && itr->first < r) { if (itr->second <= r) itr = st_erase(itr); else { itr = st_emplace_hint(itr, r, itr->second); st_erase(prev(itr)); } } if (itr != st.begin() && prev(itr)->first == l) st_erase(prev(itr)); else if (itr != st.begin() && l < prev(itr)->second) { st_emplace_hint(prev(itr), prev(itr)->first, l); st_erase(prev(itr)); } } void erase(ll l) { erase(l, l + 1); } bool include(ll k) { auto itr = st.lower_bound({k + 1, k + 1}); return itr != st.begin() && k < prev(itr)->second; } std::pair<ll, ll> find(ll k) { auto itr = st.lower_bound({k + 1, k + 1}); if (itr == st.begin()) return {-1, -1}; --itr; if (itr->second <= k) return {-1, -1}; return *itr; } }; #line 4 "test/yuki/1601.test.cpp" using namespace std; int main() { ll D, Q; cin >> D >> Q; RangeSet st; ll ans = 0; rep (Q) { ll a, b; cin >> a >> b; st.insert(a, b + 1); auto p = st.find(a); chmax(ans, p.second - p.first); cout << ans << endl; } }