結果

問題 No.674 n連勤
ユーザー ama_nuko
提出日時 2018-07-13 18:11:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,281 bytes
コンパイル時間 1,178 ms
コンパイル使用メモリ 104,476 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-08 22:05:21
合計ジャッジ時間 2,823 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e18;
const int MOD = 1e9+7;

signed main(){
    int d, q;
    cin >> d >> q;

    set<P> range;
    range.emplace(-INF-10, -INF-10);
    range.emplace(INF+10, INF+10);
    int ans = 0;
    rep(i, q){
        int a, b;
        cin >> a >> b;
        P r = make_pair(a, b);
        auto x_ = range.lower_bound(r);
        x_--;
        P x = *x_;

        if(x.second + 1 >= r.first){
            r.first = x.first;
            r.second = max(r.second, x.second);
            range.erase(x);
        }

        auto y_ = range.upper_bound(r);
        P y = *y_;
        while(y.first <= r.second + 1){
            r.second = max(r.second, y.second);
            y_ = range.erase(y_);
            y = *y_;
        }
        range.insert(r);

        int len = r.second - r.first + 1;
        if(ans < len){
            ans = len;
        }
        cout << ans << endl;
    }
    return 0;
}
0