結果
| 問題 |
No.631 Noelちゃんと電車旅行
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-19 18:31:42 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 251 ms / 2,000 ms |
| コード長 | 2,425 bytes |
| コンパイル時間 | 2,059 ms |
| コンパイル使用メモリ | 202,852 KB |
| 最終ジャッジ日時 | 2025-01-11 05:32:33 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif
template <typename T, typename Compare>
class StarrySkyTree{
int depth, size, hsize;
std::vector<T> data;
std::optional<T> f(std::optional<T> a, std::optional<T> b) const {
if(not a) return b;
if(not b) return a;
if(Compare()(*a, *b)) return a;
return b;
}
void bottom_up(int i){
if(i > size) return;
while(i >= 1){
if(i < hsize){
const auto d = *f(data[i << 1 | 0], data[i << 1 | 1]);
data[i << 1 | 0] -= d;
data[i << 1 | 1] -= d;
data[i] += d;
}
i >>= 1;
}
}
std::optional<T> get(int i, int l, int r, int s, int t, T val) const {
if(r <= s or t <= l) return std::nullopt;
if(s <= l and r <= t) return val + data[i];
return f(
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] = *f(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, std::greater<>>(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;
}