結果
| 問題 | No.674 n連勤 | 
| コンテスト | |
| ユーザー |  qLethon | 
| 提出日時 | 2020-10-22 15:50:51 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 100 ms / 2,000 ms | 
| コード長 | 1,214 bytes | 
| コンパイル時間 | 2,251 ms | 
| コンパイル使用メモリ | 199,292 KB | 
| 最終ジャッジ日時 | 2025-01-15 12:27:05 | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 17 | 
ソースコード
#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;
    }
}
            
            
            
        