結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー t98slidert98slider
提出日時 2023-03-26 20:00:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,394 bytes
コンパイル時間 3,074 ms
コンパイル使用メモリ 173,136 KB
実行使用メモリ 10,588 KB
最終ジャッジ日時 2023-10-19 13:50:10
合計ジャッジ時間 6,184 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 15 ms
4,348 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 56 ms
9,448 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 26 ms
5,292 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 10 ms
4,348 KB
testcase_27 WA -
testcase_28 AC 58 ms
7,140 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 90 ms
10,504 KB
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template <class S,S (*mapping)(S, S),S (*id)()> struct dual_segtree {
    public:
        dual_segtree() : dual_segtree(0) {}
        dual_segtree(int n) : dual_segtree(std::vector<S>(n, id())) {}
        dual_segtree(const std::vector<S>& v) : _n(int(v.size())) {
            log = ceil_pow2(_n);
            size = 1 << log;
            d = std::vector<S>(2 * size, id());
            for (int i = 0; i < _n; i++) d[size + i] = v[i];
        }
        const S& operator[](int p) const {
            assert(0 <= p && p < _n);
            p += size;
            for (int i = log; i >= 1; i--) push(p >> i);
            return d[p];
        }
        S& operator[](int p) { 
            assert(0 <= p && p < _n);
            p += size;
            for (int i = log; i >= 1; i--) push(p >> i);
            return d[p];
        }
        void apply(int p, S f) {
            assert(0 <= p && p < _n);
            p += size;
            for (int i = log; i >= 1; i--) push(p >> i);
            d[p] = mapping(f, d[p]);
        }
        void apply(int l, int r, S 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);
            }
            while (l < r) {
                if (l & 1) all_apply(l++, f);
                if (r & 1) all_apply(--r, f);
                l >>= 1;
                r >>= 1;
            }
        }
    private:
        int _n, size, log;
        std::vector<S> d;
        void all_apply(int k, S f) {
            d[k] = mapping(f, d[k]);
        }
        void push(int k) {
            all_apply(2 * k, d[k]);
            all_apply(2 * k + 1, d[k]);
            d[k] = id();
        }
        int ceil_pow2(int n) {
            int x = 0;
            while ((1U << x) < (unsigned int)(n)) x++;
            return x;
        }
};
using S = ll;
//xにfを作用させた時の値の変化
S op(S f, S x){return max(x, f);}
//作用させても変化させないもの
S id(){return 0;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K, ng = -1, ok = 1 << 30, mid;
    cin >> N >> K;
    vector<int> T(N + 2), D(N + 2);
    for(int i = 1; i <= N; i++) cin >> T[i] >> D[i];
    T[0] = -K;
    T[N + 1] = T[N] + K;
    auto f = [&](int mid){
        for(int l = 0, r = 0; l < N; l++){
            if(D[l] > mid){
                r = max(r, l + 1);
                while(r <= N && D[r] < D[l] + K){
                    if(D[r] > mid) return false;
                    r++;
                }
            }
        }
        return true;
    };
    while(ng + 1 < ok){
        mid = (ok + ng) / 2;
        if(f(mid)) ok = mid;
        else ng = mid;
    }
    dual_segtree<ll, op, id> seg(N + 3);
    for(int l = 0, r1 = 0, r2 = 0, s = 0; l <= N; l++){
        r1 = max(r1, l + 1);
        r2 = max(r2, l + 1);
        while(r1 <= N + 1 && T[r1] < T[l] + K)r1++;
        while(r2 <= N + 1 && D[r2] <= ok) r2++;
        //cerr << l << ":" << "[" << r1 << ":" << r2 << "]" << '\n';
        if(r1 <= r2) seg.apply(r1, r2 + 1, seg[l] + D[l]);
    }
    cout << ok << '\n';
    cout << accumulate(D.begin(), D.end(), 0ll) - seg[N + 2] << '\n';
}
0