結果

問題 No.674 n連勤
ユーザー qLethonqLethon
提出日時 2020-10-22 15:50:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,214 bytes
コンパイル時間 3,243 ms
コンパイル使用メモリ 204,780 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-28 14:37:11
合計ジャッジ時間 5,319 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

template <class T>
class IntervalSet{
    /*
    insert(l, r): 区間[l, r)を挿入 区間が被っているものはマージ O(logN)
    erase(l, r): 区間[l, r)と被っている区間をすべて削除 O(logN)
    */

    public:
    set<array<T, 2>> st;
    IntervalSet(T INF){
        st.insert({-INF, -INF});
        st.insert({INF, INF});
    };

    array<T, 2> insert(T l, T r){
        auto it = st.lower_bound({l, r});
        auto itl = it, itr = it;
        itl--;
        while (itl != st.begin() and l <= (*itl)[1]){
            r = max(r, (*itl)[1]);
            l = min(l, (*itl)[0]);
            itl--;
        }
        
        while (itr != st.end() and (*itr)[0] <= r){
            r = max(r, (*itr)[1]);
            itr++;
        }

        st.erase(++itl, itr);
        st.insert({l, r});

        return {l, r};
    }
};

int main(){
    int64_t d, q;
    cin >> d >> q;

    int64_t ma = 0;
    IntervalSet<int64_t> st(2e18);
    for (int i = 0; i < q; i++){
        int64_t l, r;
        cin >> l >> r;
        r++;
        auto res = st.insert(l, r);
        ma = max(ma, res[1] - res[0]);
        
        cout << ma << endl;
    }
}
0