結果

問題 No.674 n連勤
ユーザー trineutron
提出日時 2022-06-21 01:40:02
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 800 bytes
コンパイル時間 2,328 ms
コンパイル使用メモリ 201,304 KB
最終ジャッジ日時 2025-01-29 23:35:07
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

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