結果

問題 No.674 n連勤
ユーザー Pachicobue
提出日時 2018-09-14 19:43:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 1,070 bytes
コンパイル時間 1,927 ms
コンパイル使用メモリ 201,008 KB
最終ジャッジ日時 2025-01-06 13:22:47
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using ll = long long;
class DisjointSegments
{
    using T = ll;
    using P = std::pair<T, T>;

public:
    DisjointSegments() = default;
    P insert(T S, T T)
    {
        auto itl = segments.upper_bound(S), itr = segments.upper_bound(T);
        if (itl != segments.begin()) {
            if ((--itl)->second < S) { itl++; }
        }
        if (itl != itr) {
            S = std::min(S, itl->first), T = std::max(T, std::prev(itr)->second);
            segments.erase(itl, itr);
        }
        return segments[S] = T, P{S, T};
    }
    std::vector<std::pair<T, T>> data() const { return std::vector<std::pair<T, T>>{segments.begin(), segments.end()}; }

private:
    std::map<T, T> segments;
};
int main()
{
    ll D;
    int Q;
    std::cin >> D >> Q;
    DisjointSegments works;
    ll ans = 0;
    for (int q = 0; q < Q; q++) {
        ll A, B;
        std::cin >> A >> B, B++;
        const auto p = works.insert(A, B);
        ans = std::max(ans, p.second - p.first);
        std::cout << ans << std::endl;
    }
    return 0;
}
0