結果

問題 No.674 n連勤
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2018-04-13 23:23:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 323 ms / 2,000 ms
コード長 4,014 bytes
コンパイル時間 1,953 ms
コンパイル使用メモリ 179,176 KB
実行使用メモリ 8,428 KB
最終ジャッジ日時 2023-09-09 04:48:30
合計ジャッジ時間 4,651 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,348 KB
testcase_01 AC 4 ms
7,324 KB
testcase_02 AC 4 ms
7,160 KB
testcase_03 AC 5 ms
7,280 KB
testcase_04 AC 4 ms
7,148 KB
testcase_05 AC 5 ms
7,096 KB
testcase_06 AC 5 ms
7,208 KB
testcase_07 AC 5 ms
7,096 KB
testcase_08 AC 5 ms
7,208 KB
testcase_09 AC 4 ms
7,096 KB
testcase_10 AC 5 ms
7,356 KB
testcase_11 AC 30 ms
7,640 KB
testcase_12 AC 26 ms
7,664 KB
testcase_13 AC 25 ms
8,352 KB
testcase_14 AC 121 ms
8,300 KB
testcase_15 AC 230 ms
8,428 KB
testcase_16 AC 235 ms
8,356 KB
testcase_17 AC 232 ms
8,172 KB
testcase_18 AC 257 ms
8,220 KB
testcase_19 AC 323 ms
8,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<class V, int NV> struct LazySegTree { // [L,R)
    vector<V> dat, lazy; LazySegTree() { dat.resize(NV * 2, def); lazy.resize(NV * 2, ldef); }
    void update(int a, int b, V v, int k, int l, int r) { push(k, l, r); if (r <= a || b <= l) return;
        if (a <= l && r <= b) { setLazy(k, v); push(k, l, r); } else {
        update(a, b, v, k * 2 + 1, l, (l + r) / 2); update(a, b, v, k * 2 + 2, (l + r) / 2, r);
        dat[k] = comp(dat[k * 2 + 1], dat[k * 2 + 2]);}}
    V get(int a, int b, int k, int l, int r) { push(k, l, r); if (r <= a || b <= l) return def;
        if (a <= l && r <= b) return dat[k]; auto x = get(a, b, k * 2 + 1, l, (l + r) / 2);
        auto y = get(a, b, k * 2 + 2, (l + r) / 2, r); return comp(x, y);}
    void update(int a, int b, V v) { update(a, b, v, 0, 0, NV); }
    V get(int a, int b) { return get(a, b, 0, 0, NV); }
    // ---- Template ---------------------------------------------------------------------------------
    const V def = 0, ldef = -1;
    V comp(V l, V r) { return l + r; }
    void setLazy(int i, V v) { lazy[i] = v; }
    void push(int k, int l, int r) {
        if (lazy[k] != ldef) {
            // modify------------------------------
            dat[k] = lazy[k] * (r - l);
            // ------------------------------------
            if (r - l > 1) { setLazy(k * 2 + 1, lazy[k]); setLazy(k * 2 + 2, lazy[k]); }
            lazy[k] = ldef;
        }
    }
};
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/




ll D; int Q; ll A[30101], B[30101];
LazySegTree<ll, 1 << 17> st;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> D >> Q;
    rep(i, 0, Q) cin >> A[i] >> B[i];
    rep(i, 0, Q) B[i]++;

    vector<ll> dic;
    rep(i, 0, Q) dic.push_back(A[i]), dic.push_back(B[i]);
    sort(all(dic));
    dic.erase(unique(all(dic)), dic.end());

    ll ans = 0;
    rep(q, 0, Q) {
        int a = lower_bound(all(dic), A[q]) - dic.begin();
        int b = lower_bound(all(dic), B[q]) - dic.begin();

        st.update(a, b, 1);

        int L, R;

        { // for L
            int ng = -1, ok = a;
            while (ng + 1 != ok) {
                int md = (ng + ok) / 2;
                if (st.get(md, a + 1) == a + 1 - md) ok = md;
                else ng = md;
            }
            L = ok;
        }

        { // for R
            if (st.get(b, b + 1) == 0) {
                R = b;
            }
            else {
                int ok = b, ng = 1 << 17;
                while (ok + 1 != ng) {
                    int md = (ok + ng) / 2;
                    if (st.get(b, md + 1) == md - b + 1) ok = md;
                    else ng = md;
                }

                R = ng;
            }
        }

        chmax(ans, dic[R] - dic[L]);
        printf("%lld\n", ans);
    }
}
0