結果

問題 No.674 n連勤
ユーザー treeonetreeone
提出日時 2018-04-13 23:03:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 2,513 bytes
コンパイル時間 2,385 ms
コンパイル使用メモリ 209,024 KB
実行使用メモリ 4,684 KB
最終ジャッジ日時 2023-09-09 04:46:36
合計ジャッジ時間 3,938 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 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 8 ms
4,380 KB
testcase_13 AC 52 ms
4,376 KB
testcase_14 AC 52 ms
4,380 KB
testcase_15 AC 51 ms
4,380 KB
testcase_16 AC 69 ms
4,620 KB
testcase_17 AC 68 ms
4,684 KB
testcase_18 AC 65 ms
4,388 KB
testcase_19 AC 53 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

// Description: 区間をsetで管理するデータ構造(なお実装はmap).各クエリO(log区間数).
 
// #### attention! : [l, r] ( include r, not [l, r) )
class SegmentMap : public std::map<int, int> {
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(int p) const {
        auto it = upper_bound(p);
        if (it == begin() || (--it)->second < p) return end();
        return it;
    }
    // insert segment [l, r]
    void insert(int l, int 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(int l, int 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(int p, int q) const {
        const auto&& it = get(p);
        return it != end() && it->first <= q && q <= it->second;
    }
};


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int d, q;
    cin >> d >> q;
    vector<int> a(q), b(q);
    SegmentMap map(true);
    int MAX = 0;
    rep(i, 0, q){
        cin >> a[i] >> b[i];
        map.insert(a[i], b[i]);
        auto it = map.get(a[i]);
        int tmp = it->second - it->first + 1;
        chmax(MAX, tmp);
        cout << MAX << endl;
    }
}
0