結果

問題 No.631 Noelちゃんと電車旅行
ユーザー HaarHaar
提出日時 2020-04-30 20:09:50
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 235 ms / 2,000 ms
コード長 2,265 bytes
コンパイル時間 2,518 ms
コンパイル使用メモリ 200,988 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 08:02:39
合計ジャッジ時間 7,038 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 188 ms
6,816 KB
testcase_01 AC 232 ms
6,940 KB
testcase_02 AC 230 ms
6,940 KB
testcase_03 AC 232 ms
6,940 KB
testcase_04 AC 235 ms
6,940 KB
testcase_05 AC 231 ms
6,944 KB
testcase_06 AC 94 ms
6,940 KB
testcase_07 AC 45 ms
6,944 KB
testcase_08 AC 173 ms
6,944 KB
testcase_09 AC 208 ms
6,944 KB
testcase_10 AC 137 ms
6,940 KB
testcase_11 AC 125 ms
6,944 KB
testcase_12 AC 155 ms
6,944 KB
testcase_13 AC 163 ms
6,944 KB
testcase_14 AC 78 ms
6,944 KB
testcase_15 AC 131 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,944 KB
testcase_20 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>


#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif


template <typename T>
class StarrySkyTree{
  int depth, size, hsize;
  std::vector<T> data;

  const T id = std::numeric_limits<T>::lowest();

  void bottom_up(int i){
    if(i > size) return;

    while(i >= 1){
      if(i < hsize){
        const auto d = std::max(data[i << 1 | 0], data[i << 1 | 1]);
    
        data[i << 1 | 0] -= d;
        data[i << 1 | 1] -= d;
        data[i] += d;
      }

      i >>= 1;
    }
  }
  
  T get(int i, int l, int r, int s, int t, T val) const {
    if(r <= s or t <= l) return id;
    if(s <= l and r <= t) return val + data[i];
    return std::max(get(i << 1 | 0, l, (l + r) / 2, s, t, val + data[i]),
                    get(i << 1 | 1, (l + r) / 2, r, s, t, val + data[i]));
  }

public:
  StarrySkyTree(int n):
    depth(n > 1 ? 32-__builtin_clz(n-1) + 1 : 1),
    size(1 << depth),
    hsize(size / 2),    
    data(size, 0)
  {}

  void update(int l, int r, T val){
    int L = l + hsize;
    int R = r + hsize;

    while(L < R){
      if(R & 1) --R, data[R] += val;
      if(L & 1) data[L] += val, ++L;
      L >>= 1;
      R >>= 1;
    }

    bottom_up(l + hsize);
    bottom_up(r + hsize);
  }

  T get(int l, int r) const {
    return get(1, 0, hsize, l, r, 0);
  }

  template <typename U>
  void init_with_vector(std::vector<U> &a){
    for(int i = 0; i < (int)a.size(); ++i){
      data[hsize + i] = a[i];
    }

    for(int i = hsize - 1; i >= 1; --i){
      data[i] = std::max(data[i << 1 | 0], data[i << 1 | 1]);
    }

    for(int i = size - 1; i > 1; --i){
      data[i] -= data[i >> 1];
    }
  }
};



int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  
  int N;
  while(std::cin >> N){
    auto seg = StarrySkyTree<int64_t>(N-1);
        
    std::vector<int64_t> T(N-1);
    for(auto &x : T) std::cin >> x;
    
    for(int i = 0; i < N-1; ++i){
      T[i] += 3 * (N-1-i);
    }

    seg.init_with_vector(T);
    
    int M; std::cin >> M;

    for(int i = 0; i < M; ++i){
      int L, R, D; std::cin >> L >> R >> D;
      --L, --R;

      seg.update(L, R+1, D);
      
      auto ans = seg.get(0, N-1);
      std::cout << ans << std::endl;
    }
  }

  return 0;
}
0