結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー roarisroaris
提出日時 2020-12-05 17:49:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 4,446 bytes
コンパイル時間 2,906 ms
コンパイル使用メモリ 207,344 KB
実行使用メモリ 14,104 KB
最終ジャッジ日時 2023-10-13 22:22:19
合計ジャッジ時間 9,566 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 20 ms
4,620 KB
testcase_14 AC 23 ms
4,664 KB
testcase_15 AC 62 ms
7,948 KB
testcase_16 AC 114 ms
12,176 KB
testcase_17 AC 101 ms
12,480 KB
testcase_18 AC 16 ms
4,564 KB
testcase_19 AC 148 ms
13,656 KB
testcase_20 AC 46 ms
6,396 KB
testcase_21 AC 137 ms
13,896 KB
testcase_22 AC 50 ms
7,540 KB
testcase_23 AC 143 ms
13,852 KB
testcase_24 AC 35 ms
5,700 KB
testcase_25 AC 144 ms
13,672 KB
testcase_26 AC 16 ms
4,396 KB
testcase_27 AC 108 ms
12,216 KB
testcase_28 AC 97 ms
9,356 KB
testcase_29 AC 55 ms
7,816 KB
testcase_30 AC 153 ms
13,804 KB
testcase_31 AC 19 ms
4,532 KB
testcase_32 AC 20 ms
4,556 KB
testcase_33 AC 165 ms
14,068 KB
testcase_34 AC 151 ms
14,040 KB
testcase_35 AC 166 ms
14,100 KB
testcase_36 AC 137 ms
14,104 KB
testcase_37 AC 160 ms
13,984 KB
testcase_38 AC 145 ms
13,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
typedef long long ll;

ll N, K;
vector<ll> T, D;

bool judge(ll x) {
    vector<ll> l;
    rep(i, N) if (D[i]>x) l.pb(T[i+1]);
    if (l.size()==0) return true;
    rep(i, l.size()-1) if (l[i+1]-l[i]<K) return false;
    return true;
}

int ceil_pow2(int n) {
    int x = 0;
    while ((1U << x) < (unsigned int)(n)) x++;
    return x;
}

template <class S,
          S (*op)(S, S),
          S (*e)(),
          class F,
          S (*mapping)(F, S),
          F (*composition)(F, F),
          F (*id)()>
struct lazy_segtree {
  public:
    lazy_segtree() : lazy_segtree(0) {}
    lazy_segtree(int n) : lazy_segtree(std::vector<S>(n, e())) {}
    lazy_segtree(const std::vector<S>& v) : _n(int(v.size())) {
        log = ceil_pow2(_n);
        size = 1 << log;
        d = std::vector<S>(2 * size, e());
        lz = std::vector<F>(size, id());
        for (int i = 0; i < _n; i++) d[size + i] = v[i];
        for (int i = size - 1; i >= 1; i--) {
            update(i);
        }
    }

    void set(int p, S x) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        d[p] = x;
        for (int i = 1; i <= log; i++) update(p >> i);
    }

    S get(int p) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        return d[p];
    }

    S prod(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        if (l == r) return e();

        l += size;
        r += size;

        for (int i = log; i >= 1; i--) {
            if (((l >> i) << i) != l) push(l >> i);
            if (((r >> i) << i) != r) push(r >> i);
        }

        S sml = e(), smr = e();
        while (l < r) {
            if (l & 1) sml = op(sml, d[l++]);
            if (r & 1) smr = op(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }

        return op(sml, smr);
    }

    S all_prod() { return d[1]; }

    void apply(int p, F f) {
        assert(0 <= p && p < _n);
        p += size;
        for (int i = log; i >= 1; i--) push(p >> i);
        d[p] = mapping(f, d[p]);
        for (int i = 1; i <= log; i++) update(p >> i);
    }
    void apply(int l, int r, F f) {
        assert(0 <= l && l <= r && r <= _n);
        if (l == r) return;

        l += size;
        r += size;

        for (int i = log; i >= 1; i--) {
            if (((l >> i) << i) != l) push(l >> i);
            if (((r >> i) << i) != r) push((r - 1) >> i);
        }

        {
            int l2 = l, r2 = r;
            while (l < r) {
                if (l & 1) all_apply(l++, f);
                if (r & 1) all_apply(--r, f);
                l >>= 1;
                r >>= 1;
            }
            l = l2;
            r = r2;
        }

        for (int i = 1; i <= log; i++) {
            if (((l >> i) << i) != l) update(l >> i);
            if (((r >> i) << i) != r) update((r - 1) >> i);
        }
    }

  private:
    int _n, size, log;
    std::vector<S> d;
    std::vector<F> lz;

    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
    void all_apply(int k, F f) {
        d[k] = mapping(f, d[k]);
        if (k < size) lz[k] = composition(f, lz[k]);
    }
    void push(int k) {
        all_apply(2 * k, lz[k]);
        all_apply(2 * k + 1, lz[k]);
        lz[k] = id();
    }
};

ll op(ll x, ll y) {return min(x, y);}
ll e() {return 1000000000000000000;}
ll mapping(ll f, ll x) {return f+x;}
ll composition(ll f, ll g) {return f+g;}
ll id() {return 0;}

int main() {
    //ループ変数が被っていないか?
    //制約を確認しているか?
    //変数のtypoがないか?
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> K;
    T.pb(-10000000000);
    rep(i, N) {
        ll Ti, Di; cin >> Ti >> Di;
        T.pb(Ti); D.pb(Di);
    }
    
    ll l = 0, r = 10000000000;
    while (l<=r) {
        ll m = (l+r)/2;
        if (judge(m)) r = m-1;
        else l = m+1;
    }
    
    ll lim = l;
    lazy_segtree<ll, op, e, ll, mapping, composition, id> lst(N+1);
    lst.set(0, 0);
    l = 0;
    
    rep(i, N) {
        ll r = upper_bound(T.begin(), T.end(), T[i+1]-K)-T.begin();
        ll m = lst.prod(l, max(l, r));
        lst.apply(0, N+1, D[i]);
        lst.set(i+1, m);
        if (D[i]>lim) l = i+1;
    }
    
    cout << lim << endl;
    cout << lst.prod(l, N+1) << endl;
}
0