結果

問題 No.674 n連勤
ユーザー rpy3cpprpy3cpp
提出日時 2019-05-17 18:31:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 1,326 bytes
コンパイル時間 1,900 ms
コンパイル使用メモリ 176,784 KB
実行使用メモリ 4,836 KB
最終ジャッジ日時 2023-10-17 07:24:37
合計ジャッジ時間 3,753 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 11 ms
4,348 KB
testcase_14 AC 14 ms
4,348 KB
testcase_15 AC 13 ms
4,348 KB
testcase_16 AC 20 ms
4,836 KB
testcase_17 AC 21 ms
4,836 KB
testcase_18 AC 16 ms
4,348 KB
testcase_19 AC 14 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

class RangeSet{
private:
    const long long INF = 1e18 + 1e8;
    long long max_range;
    set<pair<long long, long long>> data;  // stores the ranges [L, R)
public:
    RangeSet(): max_range(0), data(){
        data.emplace(-INF, -INF);
        data.emplace(INF, INF);
    }
    void insert(long long L, long long R){        // Insert a range [L, R) to the set.
        if (L >= R) return;
        auto it = data.lower_bound(make_pair(L, R));
        if (L == it->first) return;   // [L, R) is covered by *it. L1 == L < R <= R1
        if (L <= (--it)->second){
            L = it->first;
        }else{
            ++it;
        }
        while (it->first <= R){
            R = max(R, it->second);
            it = data.erase(it);
        }
        data.insert(it, make_pair(L, R));
        max_range = max(max_range, R - L);
    }
    long long get_max_range(){
        return this->max_range;
    }
};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long D;
    int Q;
    cin >> D >> Q;
    vector<pair<long long, long long>> ABs(Q);
    for (auto & ab: ABs) cin >> ab.first >> ab.second;
    RangeSet rset;
    for (auto & ab: ABs){
        rset.insert(ab.first, ab.second + 1LL);
        cout << rset.get_max_range() << '\n';
    }
    return 0;
}
0