結果

問題 No.674 n連勤
ユーザー PachicobuePachicobue
提出日時 2018-09-14 19:43:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 1,070 bytes
コンパイル時間 2,213 ms
コンパイル使用メモリ 206,976 KB
実行使用メモリ 4,432 KB
最終ジャッジ日時 2023-09-20 07:46:56
合計ジャッジ時間 4,424 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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