結果
問題 | No.631 Noelちゃんと電車旅行 |
ユーザー | Haar |
提出日時 | 2020-04-30 19:51:09 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 239 ms / 2,000 ms |
コード長 | 2,188 bytes |
コンパイル時間 | 2,548 ms |
コンパイル使用メモリ | 208,504 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-04-10 08:02:47 |
合計ジャッジ時間 | 7,386 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 198 ms
6,812 KB |
testcase_01 | AC | 238 ms
6,940 KB |
testcase_02 | AC | 239 ms
6,940 KB |
testcase_03 | AC | 239 ms
6,940 KB |
testcase_04 | AC | 234 ms
6,940 KB |
testcase_05 | AC | 238 ms
6,940 KB |
testcase_06 | AC | 98 ms
6,944 KB |
testcase_07 | AC | 47 ms
6,940 KB |
testcase_08 | AC | 175 ms
6,940 KB |
testcase_09 | AC | 217 ms
6,940 KB |
testcase_10 | AC | 144 ms
6,940 KB |
testcase_11 | AC | 122 ms
6,940 KB |
testcase_12 | AC | 159 ms
6,940 KB |
testcase_13 | AC | 163 ms
6,940 KB |
testcase_14 | AC | 82 ms
6,944 KB |
testcase_15 | AC | 136 ms
6,944 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 |
ソースコード
#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 update(int i, int l, int r, int s, int t, T val){ if(r <= s or t <= l) return; else if(s <= l and r <= t){ data[i] += val; return; } update(i << 1 | 0, l, (l + r) / 2, s, t, val); update(i << 1 | 1, (l + r) / 2, r, s, t, val); 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; } T get(int i, int l, int r, int s, int t, T val){ 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){ update(1, 0, hsize, l, r, val); } T get(int l, int r){ 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; }