結果

問題 No.631 Noelちゃんと電車旅行
ユーザー merom686merom686
提出日時 2018-01-06 17:31:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 1,931 bytes
コンパイル時間 1,030 ms
コンパイル使用メモリ 79,080 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2024-04-10 07:48:16
合計ジャッジ時間 4,037 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
5,248 KB
testcase_01 AC 121 ms
6,144 KB
testcase_02 AC 123 ms
6,144 KB
testcase_03 AC 118 ms
6,016 KB
testcase_04 AC 119 ms
6,144 KB
testcase_05 AC 120 ms
6,016 KB
testcase_06 AC 46 ms
5,376 KB
testcase_07 AC 25 ms
5,376 KB
testcase_08 AC 87 ms
6,016 KB
testcase_09 AC 101 ms
5,376 KB
testcase_10 AC 72 ms
5,760 KB
testcase_11 AC 64 ms
5,376 KB
testcase_12 AC 82 ms
5,760 KB
testcase_13 AC 72 ms
5,376 KB
testcase_14 AC 31 ms
5,376 KB
testcase_15 AC 62 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

struct SegmentTree {
    struct Node {
        Node operator*(const Node& o) const {
            return { max(m, o.m) };
        }
        int64_t m;
    };
    using Lazy = int64_t;

    SegmentTree(int n) : e({ -((int64_t)1 << 60) }), n(n) {
        for (m = 2; m < n; m *= 2);
        t = vector<Node>(m + n + n % 2, e);
        z = vector<Lazy>(m, 0);
    }
    Node& operator[](int i) {
        return t[m + i];
    }
    const Node& root() const {
        return t[1];
    }
    void build() {
        for (int i = (n - 1 + m) / 2; i > 0; i--) {
            t[i] = t[i * 2] * t[i * 2 + 1];
        }
    }
    void range_act(int l, int r, Lazy x, int i = 1, int il = 0, int ir = -1) { 
        if (ir < 0) ir = m;
        if (l <= il && ir <= r) {
            act(i, x);
            return;
        }
        propagate(i);
        int ic = (il + ir) / 2;
        if (l < ic) range_act(l, r, x, i * 2 + 0, il, ic);
        if (ic < r) range_act(l, r, x, i * 2 + 1, ic, ir);
        t[i] = t[i * 2] * t[i * 2 + 1];
    }
    void propagate(int i) {
        if (z[i] == 0) return;
        act(i * 2 + 0, z[i]);
        act(i * 2 + 1, z[i]);
        z[i] = 0;
    }
    void act(int i, Lazy x) {
        t[i].m += x;
        if (i < m) z[i] += x;
    }
    vector<Node> t;
    vector<Lazy> z;
    const Node e;
    int n, m;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    n--;

    SegmentTree st(n);
    for (int i = 0; i < n; i++) {
        cin >> st[i].m;
        st[i].m += 3 * (n - i);
    }
    st.build();

    int m;
    cin >> m;

    for (int i = 0; i < m; i++) {
        int l, r, d;
        cin >> l >> r >> d;
        l--;

        st.range_act(l, r, d);
        cout << st.root().m << '\n';
    }

    return 0;
}
0