結果

問題 No.844 split game
ユーザー kibunakibuna
提出日時 2019-06-28 22:29:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,996 bytes
コンパイル時間 2,072 ms
コンパイル使用メモリ 177,512 KB
実行使用メモリ 10,352 KB
最終ジャッジ日時 2023-09-14 22:18:28
合計ジャッジ時間 7,143 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
5,852 KB
testcase_01 AC 62 ms
8,016 KB
testcase_02 AC 116 ms
7,264 KB
testcase_03 AC 96 ms
8,664 KB
testcase_04 AC 46 ms
5,668 KB
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 WA -
testcase_15 AC 158 ms
10,124 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 159 ms
9,868 KB
testcase_19 AC 159 ms
9,892 KB
testcase_20 AC 158 ms
10,288 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 4 ms
4,376 KB
testcase_27 WA -
testcase_28 AC 4 ms
4,380 KB
testcase_29 AC 10 ms
4,376 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 4 ms
4,376 KB
testcase_33 AC 10 ms
4,376 KB
testcase_34 AC 7 ms
4,376 KB
testcase_35 AC 13 ms
4,376 KB
testcase_36 AC 8 ms
4,376 KB
testcase_37 AC 18 ms
4,376 KB
testcase_38 AC 38 ms
4,612 KB
testcase_39 AC 83 ms
6,200 KB
testcase_40 AC 35 ms
6,020 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 1 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 1 ms
4,380 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 WA -
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 2 ms
4,376 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 2 ms
4,380 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 2 ms
4,380 KB
testcase_55 AC 1 ms
4,376 KB
testcase_56 AC 2 ms
4,376 KB
testcase_57 AC 2 ms
4,376 KB
testcase_58 AC 2 ms
4,376 KB
testcase_59 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

template <typename T = int>
struct SegmentTree {
    using F = function<T(T, T)>;
    int n;
    vector<T> dat;
    F func;
    T UNIT;

    SegmentTree(int n_, F func_, T UNIT_) : func(func_), UNIT(UNIT_) {
        n = 1;
        // full binary tree: num of leaves = n = 2^k >= n_
        while (n < n_)
            n *= 2;
        dat.assign(2 * n - 1, UNIT);
    }
    SegmentTree(vector<T> v_, F func_, T UNIT_) : func(func_), UNIT(UNIT_) {
        n = 1;
        while (n < v_.size())
            n *= 2;
        dat.assign(2 * n - 1, UNIT);
        for (int i = 0; i < v_.size(); ++i) {
            dat[n - 1 + i] = v_[i];
        }
        for (int i = n - 2; i >= 0; --i) {
            dat[i] = func(dat[2 * i + 1], dat[2 * i + 2]);
        }
    }
    void update(int k, T a) {
        // leaves are at index n-1 to 2*n-2
        k += n - 1;
        dat[k] = a;
        while (k > 0) {
            // k -> parent node
            k = (k - 1) / 2;
            // func(child nodes)
            dat[k] = func(dat[2 * k + 1], dat[2 * k + 2]);
        }
    }
    T query(int a, int b, T k, int l, int r) {
        if (r <= a || b <= l)
            return UNIT;
        if (a <= l && r <= b)
            return dat[k];
        else {
            T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
            T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
            return func(vl, vr);
        }
    }
    // get result of func() in [a, b)
    T query(int a, int b) { return query(a, b, 0, 0, n); }
};

int main() {
    ll n, m, a;
    cin >> n >> m >> a;
    vector<vector<pair<int, ll>>> rlp(n);
    for (int i = 0; i < m; ++i) {
        ll l, r, p;
        cin >> l >> r >> p;
        l--;
        r--;
        rlp[r].emplace_back(l, p);
    }
    auto f = [](ll l, ll r) { return max(l, r); };
    SegmentTree<ll> dp(n + 1, f, -INF); // max score when you add line at n
    dp.update(0, 0);
    // vl dp(n + 1, 0);
    // 0 1 2 3 4 5
    //  0 1 2 3 4 5
    for (int i = 0; i < n; ++i) {
        if (rlp[i].size() == 0) {
            ll temp = dp.query(0, i + 1) - a;
            dp.update(i + 1, temp);
        } else {
            ll tt = 0;
            if (i != n - 1)
                tt -= a;
            for (auto &lp : rlp[i]) {
                ll temp = dp.query(lp.first, lp.first + 1) + lp.second;
                if (i != n - 1)
                    temp -= a;
                chmax(tt, temp);
            }
            dp.update(i + 1, tt);
        }
    }
    ll ret = dp.query(0, n + 1);
    cout << ret << "\n";
    return 0;
}
0