結果

問題 No.674 n連勤
ユーザー gyouzasushigyouzasushi
提出日時 2023-01-19 15:49:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 4,755 bytes
コンパイル時間 1,035 ms
コンパイル使用メモリ 89,972 KB
実行使用メモリ 4,540 KB
最終ジャッジ日時 2023-09-04 03:25:56
合計ジャッジ時間 3,127 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 7 ms
4,380 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 69 ms
4,376 KB
testcase_14 AC 72 ms
4,376 KB
testcase_15 AC 67 ms
4,380 KB
testcase_16 AC 87 ms
4,540 KB
testcase_17 AC 87 ms
4,376 KB
testcase_18 AC 77 ms
4,380 KB
testcase_19 AC 72 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "test/yukicoder/1601.test.cpp"
#define PROBLEM "https://yukicoder.me/problems/1601"

#include <iostream>

#line 2 "datastructure/range_map.hpp"
#include <algorithm>
#include <cassert>
#include <map>
#include <optional>
#include <vector>
template <typename T, typename U>
struct range_map {
public:
    range_map(bool merge_adjacent_segment = true)
        : merge_adjacent_segment(merge_adjacent_segment) {
    }
    void clear() {
        mp.clear();
    }
    size_t size() {
        return mp.size();
    }
    std::optional<std::pair<T, T>> contains(T l, T r) {
        assert(l <= r);
        auto it = mp.upper_bound(l);
        if (it == mp.begin()) return std::nullopt;
        it--;
        if (it->first > l) return std::nullopt;
        if (r > it->second.first) return std::nullopt;
        return std::make_pair(it->first, it->second.first);
    }
    std::optional<std::pair<T, T>> contains(T p) {
        return is_covered(p, p);
    }
    void insert(T l, T r, U x) {
        assert(l <= r);
        auto it_l = mp.upper_bound(l);
        auto it_r = mp.upper_bound(r + int(merge_adjacent_segment));
        if (it_l != mp.begin()) {
            if (std::prev(it_l)->second.first >=
                    l - int(merge_adjacent_segment) &&
                std::prev(it_l)->second.second == x) {
                it_l--;
            }
        }
        for (auto it = it_l; it != it_r; it = mp.erase(it)) {
            l = std::min(l, it->first);
            r = std::max(r, it->second.first);
        }
        mp[l] = {r, x};
    }
    template <class op_erase, class op_insert>
    void insert(T l, T r, U x, const op_erase &f, const op_insert &g) {
        assert(l <= r);
        auto it_l = mp.upper_bound(l);
        auto it_r = mp.upper_bound(r + int(merge_adjacent_segment));
        if (it_l != mp.begin()) {
            if (std::prev(it_l)->second.first >=
                    l - int(merge_adjacent_segment) &&
                std::prev(it_l)->second.second == x) {
                it_l--;
            }
        }
        for (auto it = it_l; it != it_r; it = mp.erase(it)) {
            f(it->first, it->second.first, it->second.second);
            l = std::min(l, it->first);
            r = std::max(r, it->second.first);
        }
        mp[l] = {r, x};
        g(l, r, x);
    }
    void erase(T l, T r) {
        assert(l <= r);
        auto it_l = mp.upper_bound(l);
        auto it_r = mp.upper_bound(r);
        if (it_l != mp.begin()) {
            if (std::prev(it_l)->second.first >= l) {
                it_l--;
            }
        }
        T nl = std::min(l, it_l->first);
        T nr = std::max(r, std::prev(it_r)->second.first);
        U nl_x = it_l->second.second;
        U nr_x = std::prev(it_r)->second.second;
        for (auto it = it_l; it != it_r; it = mp.erase(it)) {
        }
        if (nl < l) mp[nl] = {l - 1, nl_x};
        if (r < nr) mp[r + 1] = {nr, nr_x};
    }
    template <class op_erase, class op_insert>
    void erase(T l, T r, const op_erase &f, const op_insert &g) {
        assert(l <= r);
        auto it_l = mp.upper_bound(l);
        auto it_r = mp.upper_bound(r);
        if (it_l != mp.begin()) {
            if (std::prev(it_l)->second.first >= l) {
                it_l--;
            }
        }
        T nl = std::min(l, it_l->first);
        T nr = std::max(r, std::prev(it_r)->second.first);
        U nl_x = it_l->second.second;
        U nr_x = std::prev(it_r)->second.second;
        for (auto it = it_l; it != it_r; it = mp.erase(it)) {
            f(it->first, it->second.first, it->second.second);
        }
        if (nl < l) {
            mp[nl] = {l - 1, nl_x};
            g(nl, l - 1, nl_x);
        }
        if (r < nr) {
            mp[r + 1] = {nr, nr_x};
            g(r + 1, nr, nr_x);
        }
    }

private:
    bool merge_adjacent_segment;
    std::map<T, std::pair<T, U>> mp;
};
#line 3 "datastructure/range_set.hpp"
template <typename T>
struct range_set : range_map<T, bool> {
    using Base = range_map<T, bool>;
    using Base::range_map;
    void insert(T l, T r) {
        Base::insert(l, r, true);
    }
    template <class op_erase, class op_insert>
    void insert(T l, T r, const op_erase &f, const op_insert &g) {
        Base::insert(l, r, true, f, g);
    }
};
#line 6 "test/yukicoder/1601.test.cpp"
int main() {
    long long d;
    int q;
    std::cin >> d >> q;
    range_set<long long> st;
    long long ans = 0;
    while (q--) {
        long long a, b;
        std::cin >> a >> b;
        st.insert(
            a, b, [](long long l, long long r, bool x) {},
            [&](long long l, long long r, bool x) {
                ans = std::max(ans, r - l + 1);
            });
        std::cout << ans << '\n';
    }
}
0