結果

問題 No.631 Noelちゃんと電車旅行
ユーザー merom686
提出日時 2018-01-06 17:31:02
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 1,931 bytes
コンパイル時間 732 ms
コンパイル使用メモリ 79,312 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-02 09:31:50
合計ジャッジ時間 3,879 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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