結果
問題 | No.631 Noelちゃんと電車旅行 |
ユーザー | ats5515 |
提出日時 | 2018-01-05 21:44:17 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 301 ms / 2,000 ms |
コード長 | 2,369 bytes |
コンパイル時間 | 1,037 ms |
コンパイル使用メモリ | 87,084 KB |
実行使用メモリ | 8,240 KB |
最終ジャッジ日時 | 2023-07-25 15:40:32 |
合計ジャッジ時間 | 6,625 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 219 ms
4,376 KB |
testcase_01 | AC | 299 ms
8,240 KB |
testcase_02 | AC | 300 ms
8,016 KB |
testcase_03 | AC | 301 ms
8,144 KB |
testcase_04 | AC | 299 ms
8,080 KB |
testcase_05 | AC | 296 ms
8,032 KB |
testcase_06 | AC | 123 ms
5,504 KB |
testcase_07 | AC | 67 ms
5,780 KB |
testcase_08 | AC | 228 ms
7,884 KB |
testcase_09 | AC | 280 ms
5,432 KB |
testcase_10 | AC | 190 ms
7,720 KB |
testcase_11 | AC | 170 ms
5,768 KB |
testcase_12 | AC | 210 ms
7,880 KB |
testcase_13 | AC | 196 ms
4,460 KB |
testcase_14 | AC | 92 ms
4,380 KB |
testcase_15 | AC | 169 ms
4,456 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,376 KB |
testcase_20 | AC | 2 ms
4,384 KB |
ソースコード
#include <iostream> #include <vector> #include <map> #include <set> #include <queue> #include <string> #include <iomanip> #include <algorithm> #include <cmath> #include <stdio.h> using namespace std; #define int long long int MOD = 1000000007; template <typename T> class segment_tree { public: segment_tree(int n_) : n(__lowest_power_of_2(n_)), dat(n * 2, 0), lazy(n * 2, 0) {} template <typename Iterator> segment_tree(Iterator left, Iterator right) : n(__lowest_power_of_2(std::distance(left, right))), dat(n * 2, 0), lazy(n * 2, 0) { std::copy(left + n, right + n, dat.begin()); for (int i = n - 1; i >= 1; --i) { dat[i] = dat[i * 2] + dat[i * 2 + 1]; } } private: int n; std::vector<T> dat, lazy; static const T INF = std::numeric_limits<T>::max() / 2; public: void add(int ql, int qr, const T &x) { __add(1, 0, n, ql, qr, x); } T max(int ql, int qr) { return __max(1, 0, n, ql, qr); } private: void __flush_lazy(int v) { dat[v] += lazy[v]; if (v < n) { lazy[v * 2] += lazy[v]; lazy[v * 2 + 1] += lazy[v]; } lazy[v] = 0; } void __update_dat(int v) { dat[v] = std::max(dat[v * 2], dat[v * 2 + 1]); } void __add(int n, int l, int r, const int ql, const int qr, const T &x) { __flush_lazy(n); if (r <= ql || qr <= l) { return; } else if (ql <= l && r <= qr) { lazy[n] += x; __flush_lazy(n); } else { int m = (l + r) / 2; __add(n * 2, l, m, ql, qr, x); __add(n * 2 + 1, m, r, ql, qr, x); __update_dat(n); } } T __max(int n, int l, int r, const int ql, const int qr) { __flush_lazy(n); if (r <= ql || qr <= l) { return -INF; } else if (ql <= l && r <= qr) { return dat[n]; } else { int m = (l + r) / 2; T res_left = __max(n * 2, l, m, ql, qr); T res_right = __max(n * 2 + 1, m, r, ql, qr); __update_dat(n); return std::max(res_left, res_right); } } int __lowest_power_of_2(int x) const { int res = 1; while (res < x) res <<= 1; return res; } }; ; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N; segment_tree<int> sg(N - 1); vector<int> A(N); int res = 0; for (int i = 0; i < N - 1; i++) { cin >> A[i]; A[i] -= 3 * i; sg.add(i, i + 1, A[i]); } int l, r, d; cin >> M; for (int i = 0; i < M; i++) { cin >> l >> r >> d; l--; sg.add(l, r, d); cout << 3 * (N - 1) + sg.max(0, N) << endl; } }