結果

問題 No.674 n連勤
ユーザー finefine
提出日時 2018-04-13 22:44:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 2,166 bytes
コンパイル時間 1,681 ms
コンパイル使用メモリ 173,148 KB
実行使用メモリ 4,516 KB
最終ジャッジ日時 2023-09-09 04:42:26
合計ジャッジ時間 3,254 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

// Description: 区間をsetで管理するデータ構造(なお実装はmap).各クエリO(log区間数).
 
// #### attention! : [l, r] ( include r, not [l, r) )
class SegmentMap : public std::map<ll, ll> {
private:
    bool flagToMergeAdjacentSegment;
public:
    // if merge [l, c] and [c+1, r], set flagToMergeAdjacentSegment to true
    SegmentMap(bool flagToMergeAdjacentSegment) :
        flagToMergeAdjacentSegment(flagToMergeAdjacentSegment) {}
    // __exist -> iterator pair(l, r) (contain p)
    // noexist -> map.end()
    /*
    auto get(ll p) const {
        auto it = upper_bound(p);
        if (it == begin() || (--it)->second < p) return end();
        return it;
    }*/
    // insert segment [l, r]
    void insert(ll& l, ll& r) {
        auto itl = upper_bound(l), itr = upper_bound(r + flagToMergeAdjacentSegment);
        if (itl != begin()) {
            if ((--itl)->second < l - flagToMergeAdjacentSegment) ++itl;
        }
        if (itl != itr) {
            l = std::min(l, itl->first);
            r = std::max(r, std::prev(itr)->second);
            erase(itl, itr);
        }
        (*this)[l] = r;
    }
    // remove segment [l, r]
    void remove(ll l, ll r) {
        auto itl = upper_bound(l), itr = upper_bound(r);
        if (itl != begin()) {
            if ((--itl)->second < l) ++itl;
        }
        if (itl == itr) return;
        int tl = std::min(l, itl->first), tr = std::max(r, std::prev(itr)->second);
        erase(itl, itr);
        if (tl < l) (*this)[tl] = l - 1;
        if (r < tr) (*this)[r + 1] = tr;
    }
    // Is p and q in same segment?
    /*
    bool same(signed p, signed q) const {
        const auto&& it = get(p);
        return it != end() && it->first <= q && q <= it->second;
    }*/
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll d;
    int q;
    cin >> d >> q;
    SegmentMap sm(true);
    ll ans = 0;
    for (int i = 0; i < q; i++) {
        ll a, b;
        cin >> a >> b;
        sm.insert(a, b);
        ans = max(ans, b - a + 1);
        cout << ans << endl;
    }
    return 0;
}
0