結果
問題 |
No.631 Noelちゃんと電車旅行
|
ユーザー |
![]() |
提出日時 | 2018-02-14 00:15:54 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 406 ms / 2,000 ms |
コード長 | 2,014 bytes |
コンパイル時間 | 1,699 ms |
コンパイル使用メモリ | 171,096 KB |
実行使用メモリ | 9,596 KB |
最終ジャッジ日時 | 2024-10-02 09:36:46 |
合計ジャッジ時間 | 8,056 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> using namespace std; struct starry_sky_tree { private: const static long long inf = 1e18; const int N; std::vector<long long> addVec, minVec; std::function<bool(long long, long long)> comp; void add(int l, int r, long long val, int k, int L, int R) { //cerr << l << " " << r << " " << L << " " << R << endl; if (R <= l || r <= L) { return; } if (l <= L && R <= r) { this->addVec[k] += val; return; } this->add(l, r, val, k * 2 + 1, L, (L + R) / 2); this->add(l, r, val, k * 2 + 2, (L + R) / 2, R); this->minVec[k] = std::min(addVec[k * 2 + 1] + minVec[k * 2 + 1], addVec[k * 2 + 2] + minVec[k * 2 + 2], comp); } long long get(int l, int r, int k, int L, int R) { if (R <= l || r <= L) { return inf; } if (l <= L && R <= r) { return addVec[k] + minVec[k]; } auto left = this->get(l, r, k * 2 + 1, L, (L + R) / 2); auto right = this->get(l, r, k * 2 + 2, (L + R) / 2, R); return std::min(left, right, comp) + addVec[k]; } public: starry_sky_tree(const int n, const long long def = inf, const std::function<bool(long long, long long)> _comp = std::less<long long>()) : N(n), addVec(n << 2, 0), minVec(n << 2, def), comp(_comp) {} void add(int l, int r, long long v) { this->add(l, r, v, 0, 0, N); } long long get(int l, int r) { return this->get(l, r, 0, 0, N); } }; int main() { int N; cin >> N; starry_sky_tree sst(N, 0, greater<long long>()); for (int i = 0; i < N - 1; i++) { int t; cin >> t; sst.add(i, i + 1, t + (N - i - 1) * 3); } int M; cin >> M; for (int i = 0; i < M; i++) { int l, r, d; cin >> l >> r >> d; sst.add(l - 1, r, d); cout << sst.get(0, N) << endl; } }