結果

問題 No.631 Noelちゃんと電車旅行
ユーザー parukiparuki
提出日時 2018-01-05 21:52:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 304 ms / 2,000 ms
コード長 3,160 bytes
コンパイル時間 1,704 ms
コンパイル使用メモリ 170,816 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2024-04-10 07:42:13
合計ジャッジ時間 6,958 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 218 ms
6,812 KB
testcase_01 AC 301 ms
7,552 KB
testcase_02 AC 304 ms
7,680 KB
testcase_03 AC 300 ms
7,552 KB
testcase_04 AC 296 ms
7,808 KB
testcase_05 AC 303 ms
7,808 KB
testcase_06 AC 113 ms
6,940 KB
testcase_07 AC 63 ms
6,940 KB
testcase_08 AC 215 ms
7,680 KB
testcase_09 AC 250 ms
6,940 KB
testcase_10 AC 181 ms
7,680 KB
testcase_11 AC 150 ms
6,944 KB
testcase_12 AC 195 ms
7,808 KB
testcase_13 AC 184 ms
6,944 KB
testcase_14 AC 90 ms
6,940 KB
testcase_15 AC 158 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

template<class Val, class Cmp, Val DEF>
struct LazySegtreeRMQ {
    int dataSize, givenL, givenR;
    vector<Val> lazy, dat;
    Cmp cmp;
    LazySegtreeRMQ(int n) {
        dataSize = 1;
        while (dataSize < n)dataSize *= 2;
        dat = lazy = vector<Val>(dataSize * 2, DEF);
    }
    void propagate(int index, int curL, int curR) {
        // 自分の値をlazyにもとづいて書き換えて自分のlazyをクリア。
        // 子のlazyを書き換える。
        if (lazy[index] != DEF) {
            dat[index] += lazy[index];
            if (curR - curL > 1) {
                lazy[index * 2] += lazy[index];
                lazy[index * 2 + 1] += lazy[index];
            }
            lazy[index] = DEF;
        }
    }

    // [curL, curR) を評価する
    void update(int index, int curL, int curR, Val x) {
        // 範囲外であろうとpropagateは必ず呼ぶ。そうでないと、親がうまく評価されない
        propagate(index, curL, curR);
        if (givenL <= curL && curR <= givenR) {
            lazy[index] = x;
            // 直接書き換えないでindexのlazyを書き換えてpropagateを呼ぶ
            propagate(index, curL, curR);
        } else if (curR > givenL && givenR > curL) {
            int mid = (curL + curR) / 2, lc = index * 2, rc = lc + 1;
            update(lc, curL, mid, x);
            update(rc, mid, curR, x);
            dat[index] = cmp(dat[lc], dat[rc]) ? dat[lc] : dat[rc];
        }
    }

    void update(int l, int r, Val x) {
        givenL = l;
        givenR = r;
        update(1, 0, dataSize, x);
    }

    Val query(int l, int r) {
        givenL = l;
        givenR = r;
        return query(1, 0, dataSize);
    }

    Val query(int index, int curL, int curR) {
        // 範囲外
        if (curR <= givenL || givenR <= curL)return DEF;
        propagate(index, curL, curR);
        if (givenL <= curL && curR <= givenR) {
            return dat[index];
        } else {
            Val lv = query(index * 2, curL, (curL + curR) / 2);
            Val rv = query(index * 2 + 1, (curL + curR) / 2, curR);
            return cmp(lv, rv) ? lv : rv;
        }
    }
};

int N, T[100005], M;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N;
    rep(i, N - 1)cin >> T[i];

    LazySegtreeRMQ<ll, greater<ll>, 0> rmq(N - 1);
    rep(i, N - 1) {
        rmq.update(i, i+1, T[i] + (N - 1-i) * 3);
    }

    cin >> M;
    rep(i, M) {
        int L, R, D;
        cin >> L >> R >> D;
        --L;
        rmq.update(L, R, D);
        cout << rmq.query(0, N - 1) << endl;
    }
}
0