結果

問題 No.674 n連勤
ユーザー qLethonqLethon
提出日時 2020-10-22 14:39:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,179 bytes
コンパイル時間 2,106 ms
コンパイル使用メモリ 205,612 KB
実行使用メモリ 4,528 KB
最終ジャッジ日時 2023-09-28 14:36:34
合計ジャッジ時間 3,733 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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]){
            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