結果

問題 No.631 Noelちゃんと電車旅行
ユーザー RyuRyu
提出日時 2018-07-02 18:02:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 259 ms / 2,000 ms
コード長 3,085 bytes
コンパイル時間 1,128 ms
コンパイル使用メモリ 93,932 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-10 07:53:36
合計ジャッジ時間 5,959 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 203 ms
5,888 KB
testcase_01 AC 255 ms
11,264 KB
testcase_02 AC 253 ms
11,136 KB
testcase_03 AC 253 ms
11,264 KB
testcase_04 AC 248 ms
11,264 KB
testcase_05 AC 259 ms
11,136 KB
testcase_06 AC 99 ms
6,912 KB
testcase_07 AC 49 ms
6,528 KB
testcase_08 AC 192 ms
10,240 KB
testcase_09 AC 230 ms
8,448 KB
testcase_10 AC 157 ms
9,856 KB
testcase_11 AC 137 ms
7,552 KB
testcase_12 AC 173 ms
10,240 KB
testcase_13 AC 175 ms
6,400 KB
testcase_14 AC 81 ms
5,376 KB
testcase_15 AC 146 ms
6,144 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 <algorithm>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <cstring>
#include <queue>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for (int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define Cout(obj) cout << obj << endl
#define Size(obj) (int)(obj).size()
#define fcout cout << fixed << setprecision(10)
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

template <typename T>
struct LazzySegTreeMax
{
  private:
    ll N = 1;
    vector<T> node, lazy;

  public:
    LazzySegTreeMax(vector<T> vec)
    {
        ll size = Size(vec);

        while (N < size)
        {
            N *= 2;
        }

        node.resize(2 * N - 1);
        lazy.resize(2 * N - 1, 0);

        REP(i, size)
        {
            node[i + N - 1] = vec[i] + (size - i) * 3;
        }

        for (int i = N - 2; 0 <= i; i--)
        {
            node[i] = max(node[2 * i + 1], node[2 * i + 2]);
        }
    }

    void eval(int k, int l, int r)
    {
        if (lazy[k] != 0)
        {
            node[k] += lazy[k];

            if (r - l > 1)
            {
                lazy[2 * k + 1] += lazy[k];
                lazy[2 * k + 2] += lazy[k];
            }

            lazy[k] = 0;
        }
    }

    void add(int a, int b, T value, int k = 0, int l = 0, int r = -1)
    {
        if (r < 0)
            r = N;

        eval(k, l, r);

        if (r <= a || b <= l)
            return;

        if (a <= l && r <= b)
        {
            lazy[k] += value;
            eval(k, l, r);
        }
        else
        {
            add(a, b, value, 2 * k + 1, l, (l + r) / 2);
            add(a, b, value, 2 * k + 2, (l + r) / 2, r);

            node[k] = max(node[2 * k + 1], node[2 * k + 2]);
        }
    }

    T getMax(int a, int b, int k = 0, int l = 0, int r = -1)
    {
        if (r < 0)
        {
            r = N;
        }

        eval(k, l, r);

        if (r <= a || b <= l)
        {
            return -iINF;
        }

        if (a <= l && r <= b)
        {
            return node[k];
        }

        T vl = getMax(a, b, 2 * k + 1, l, (l + r) / 2);
        T vr = getMax(a, b, 2 * k + 2, (l + r) / 2, r);

        return max(vl, vr);
    }
};

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

    int N;
    cin >> N;
    vector<ll> T(N - 1);

    REP(i, N - 1)
    {
        cin >> T[i];
    }

    int M;
    cin >> M;

    vector<ll> L(M), R(M), D(M);

    REP(i, M)
    {
        cin >> L[i] >> R[i] >> D[i];
    }

    LazzySegTreeMax<ll> seg(T);

    REP(i, M)
    {
        seg.add(L[i] - 1, R[i], D[i]);
        Cout(seg.getMax(0, N));
    }

    return 0;
}
0