結果
問題 | No.631 Noelちゃんと電車旅行 |
ユーザー | Haar |
提出日時 | 2020-04-30 19:48:20 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 367 ms / 2,000 ms |
コード長 | 2,130 bytes |
コンパイル時間 | 3,034 ms |
コンパイル使用メモリ | 209,452 KB |
実行使用メモリ | 6,196 KB |
最終ジャッジ日時 | 2023-07-25 16:01:36 |
合計ジャッジ時間 | 9,584 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 290 ms
4,376 KB |
testcase_01 | AC | 367 ms
5,884 KB |
testcase_02 | AC | 361 ms
5,916 KB |
testcase_03 | AC | 362 ms
6,196 KB |
testcase_04 | AC | 364 ms
5,944 KB |
testcase_05 | AC | 361 ms
5,884 KB |
testcase_06 | AC | 150 ms
4,452 KB |
testcase_07 | AC | 76 ms
4,900 KB |
testcase_08 | AC | 267 ms
5,820 KB |
testcase_09 | AC | 323 ms
4,452 KB |
testcase_10 | AC | 218 ms
5,684 KB |
testcase_11 | AC | 199 ms
4,660 KB |
testcase_12 | AC | 245 ms
5,816 KB |
testcase_13 | AC | 252 ms
4,380 KB |
testcase_14 | AC | 117 ms
4,380 KB |
testcase_15 | AC | 208 ms
4,376 KB |
testcase_16 | AC | 2 ms
4,380 KB |
testcase_17 | AC | 2 ms
4,376 KB |
testcase_18 | AC | 2 ms
4,380 KB |
testcase_19 | AC | 2 ms
4,380 KB |
testcase_20 | AC | 2 ms
4,380 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(){ 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; }