結果

問題 No.631 Noelちゃんと電車旅行
ユーザー sekiya9311sekiya9311
提出日時 2018-02-14 00:15:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 390 ms / 2,000 ms
コード長 2,014 bytes
コンパイル時間 1,714 ms
コンパイル使用メモリ 168,712 KB
実行使用メモリ 9,608 KB
最終ジャッジ日時 2024-04-10 07:52:43
合計ジャッジ時間 7,993 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 277 ms
6,816 KB
testcase_01 AC 390 ms
9,440 KB
testcase_02 AC 387 ms
9,608 KB
testcase_03 AC 386 ms
9,560 KB
testcase_04 AC 385 ms
9,460 KB
testcase_05 AC 386 ms
9,456 KB
testcase_06 AC 151 ms
6,944 KB
testcase_07 AC 93 ms
6,940 KB
testcase_08 AC 291 ms
8,192 KB
testcase_09 AC 340 ms
6,940 KB
testcase_10 AC 243 ms
7,980 KB
testcase_11 AC 216 ms
7,168 KB
testcase_12 AC 278 ms
8,540 KB
testcase_13 AC 242 ms
6,944 KB
testcase_14 AC 112 ms
6,940 KB
testcase_15 AC 221 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

struct starry_sky_tree {
private:
    const static long long inf = 1e18;
    const int N;
    std::vector<long long> addVec, minVec;
    std::function<bool(long long, long long)> comp;
    void add(int l, int r, long long val, int k, int L, int R) {
        //cerr << l << " " << r << " " << L << " " << R << endl;
        if (R <= l || r <= L) {
            return;
        }
        if (l <= L && R <= r) {
            this->addVec[k] += val;
            return;
        }
        this->add(l, r, val, k * 2 + 1, L, (L + R) / 2);
        this->add(l, r, val, k * 2 + 2, (L + R) / 2, R);
        this->minVec[k] = std::min(addVec[k * 2 + 1] + minVec[k * 2 + 1],
                                   addVec[k * 2 + 2] + minVec[k * 2 + 2], comp);
    }
    long long get(int l, int r, int k, int L, int R) {
        if (R <= l || r <= L) {
            return inf;
        }
        if (l <= L && R <= r) {
            return addVec[k] + minVec[k];
        }
        auto left = this->get(l, r, k * 2 + 1, L, (L + R) / 2);
        auto right = this->get(l, r, k * 2 + 2, (L + R) / 2, R);
        return std::min(left, right, comp) + addVec[k];
    }
public:
    starry_sky_tree(const int n, const long long def = inf,
                    const std::function<bool(long long, long long)> _comp = std::less<long long>())
        : N(n), addVec(n << 2, 0),
          minVec(n << 2, def), comp(_comp) {}
    void add(int l, int r, long long v) {
        this->add(l, r, v, 0, 0, N);
    }
    long long get(int l, int r) {
        return this->get(l, r, 0, 0, N);
    }
};

int main() {
    int N;
    cin >> N;
    starry_sky_tree sst(N, 0, greater<long long>());
    for (int i = 0; i < N - 1; i++) {
        int t;
        cin >> t;
        sst.add(i, i + 1, t + (N - i - 1) * 3);
    }
    int M;
    cin >> M;
    for (int i = 0; i < M; i++) {
        int l, r, d;
        cin >> l >> r >> d;
        sst.add(l - 1, r, d);
        cout << sst.get(0, N) << endl;
    }
}
0