結果

問題 No.674 n連勤
ユーザー trineutrontrineutron
提出日時 2022-06-21 01:40:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 800 bytes
コンパイル時間 2,266 ms
コンパイル使用メモリ 201,644 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 16:13:58
合計ジャッジ時間 3,816 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

int main() {
    constexpr int64_t inf = 2e18;
    int64_t d, q;
    cin >> d >> q;

    map<int64_t, int64_t> mp;
    mp[-inf] = -inf;
    mp[inf] = inf;
    int64_t ans = 0;
    for (int i = 0; i < q; i++) {
        int64_t a, b;
        cin >> a >> b;
        int64_t l = a, r = b;
        auto it = mp.upper_bound(a);
        it--;
        assert(it->first <= a);
        if (it->second >= a - 1) {
            l = it->first;
            r = max(r, it->second);
            mp.erase(it);
        }
        it = mp.upper_bound(a);
        while (it->first <= b + 1) {
            r = max(r, it->second);
            it = mp.erase(it);
        }
        mp[l] = r;
        ans = max(ans, r - l + 1);
        cout << ans << endl;
    }
    return 0;
}
0