結果

問題 No.631 Noelちゃんと電車旅行
ユーザー pekempeypekempey
提出日時 2018-01-05 22:40:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 332 ms / 2,000 ms
コード長 780 bytes
コンパイル時間 767 ms
コンパイル使用メモリ 70,472 KB
実行使用メモリ 7,244 KB
最終ジャッジ日時 2024-04-10 07:42:43
合計ジャッジ時間 6,677 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 257 ms
6,812 KB
testcase_01 AC 326 ms
7,244 KB
testcase_02 AC 332 ms
7,240 KB
testcase_03 AC 328 ms
7,244 KB
testcase_04 AC 329 ms
7,244 KB
testcase_05 AC 323 ms
7,240 KB
testcase_06 AC 130 ms
6,940 KB
testcase_07 AC 78 ms
6,940 KB
testcase_08 AC 245 ms
6,940 KB
testcase_09 AC 290 ms
6,940 KB
testcase_10 AC 202 ms
6,944 KB
testcase_11 AC 182 ms
6,944 KB
testcase_12 AC 228 ms
6,940 KB
testcase_13 AC 223 ms
6,944 KB
testcase_14 AC 107 ms
6,940 KB
testcase_15 AC 186 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,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int N = 1 << 17;
long long dat[N * 2];
long long uni[N * 2];

void update(int l, int r, long long v, int k = 1, int ll = 0, int rr = N) {
  if (rr <= l || r <= ll) return;
  if (l <= ll && rr <= r) {
    dat[k] += v;
    uni[k] += v;
    return;
  }
  update(l, r, v, k * 2 + 0, ll, ll + rr >> 1);
  update(l, r, v, k * 2 + 1, ll + rr >> 1, rr);
  dat[k] = max(dat[k * 2], dat[k * 2 + 1]) + uni[k];
}

int main() {
  int n;
  cin >> n;

  for (int i = 0; i < n - 1; i++) {
    long long t;
    cin >> t;
    update(i, i + 1, t + (n - i - 1) * 3LL);
  }

  int q;
  cin >> q;

  while (q--) {
    int l, r, d;
    cin >> l >> r >> d;
    update(l - 1, r, d);
    cout << dat[1] << endl;
  }
}
0