結果
問題 | No.631 Noelちゃんと電車旅行 |
ユーザー | Pachicobue |
提出日時 | 2018-01-05 22:37:16 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 7,913 bytes |
コンパイル時間 | 2,183 ms |
コンパイル使用メモリ | 210,796 KB |
実行使用メモリ | 12,580 KB |
最終ジャッジ日時 | 2024-06-02 10:21:07 |
合計ジャッジ時間 | 7,155 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
ソースコード
#include <bits/stdc++.h> #define VARNAME(x) #x #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; using ld = long double; template <typename T> vector<T> Vec(int n, T v) { return vector<T>(n, v); } template <class... Args> auto Vec(int n, Args... args) { auto val = Vec(args...); return vector<decltype(val)>(n, move(val)); } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "sz:" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template <typename S, typename T> ostream& operator<<(ostream& os, const pair<S, T>& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = (ll)1e9 + 7LL; constexpr ld PI = static_cast<ld>(3.1415926535898); template <typename T> constexpr T INF = numeric_limits<T>::max() / 10; template <typename Base> class SegmentTree { public: using BaseAlgebra = Base; using AccMonoid = typename BaseAlgebra::AccMonoid; using OpMonoid = typename BaseAlgebra::OpMonoid; using T = typename BaseAlgebra::T; using F = typename BaseAlgebra::OpMonoid::T; SegmentTree(const int n) : data_num(n), size(1 << (1 + __lg(2 * data_num - 1))), half(size >> 1), value(size, AccMonoid::identity()), action(size, OpMonoid::identity()) { assert(n > 0); } SegmentTree(const std::vector<T>& val) : data_num(val.size()), size(1 << (1 + __lg(2 * data_num - 1))), half(size >> 1), value(size), action(size, OpMonoid::identity()) { for (int data = 0; data < half; data++) { if (data < data_num) { value[data + half] = val[data]; } else { value[data + half] = AccMonoid::identity(); } } for (int node = half - 1; node >= 1; node--) { value[node] = acc(value[2 * node], value[2 * node + 1]); } } void initialize() { for (int i = 0; i < size; i++) { value[i] = AccMonoid::identity(); action[i] = OpMonoid::identity(); } } void initialize(const vector<T>& val) { for (int data = 0; data < half; data++) { if (data < data_num) { value[data + half] = val[data]; } else { value[data + half] = AccMonoid::identity(); } } for (int node = half - 1; node >= 1; node--) { value[node] = acc(value[2 * node], value[2 * node + 1]); } } T get(const int a) const { assert(0 <= a and a < data_num); return accumulate(a, a + 1); } void set(const int a, const T& val) { assert(0 <= a and a < data_num); const int node = a + half; value[node] = val; for (int i = node / 2; i > 0; i /= 2) { value[i] = acc(value[2 * i], value[2 * i + 1]); } } T accumulate(const int a, const int b) const // Accumulate (a,b] { assert(0 <= a and a < b and b <= data_num); return accumulateRec(1, 0, half, a, b); } void modify(const int a, const int b, const F& f) // Apply f on (a,b] { assert(0 <= a and a < b and b <= data_num); if (f == OpMonoid::identity()) { return; } modifyRec(1, 0, half, a, b, f); } int query(const int a, const int b) const // query (a,b] { assert(0 <= a and a < b and b <= data_num); return queryRec(1, 0, half, a, b); } private: void modifyRec(const int range_index, const int range_left, const int range_right, const int op_left, const int op_right, const F& f) { if (op_left <= range_left and range_right <= op_right) { value[range_index] = act(f, value[range_index]); action[range_index] = compose(f, action[range_index]); } else if (range_right <= op_left or op_right <= range_left) { // Do nothing } else { modifyRec(2 * range_index, range_left, (range_left + range_right) / 2, 0, half, action[range_index]); modifyRec(2 * range_index, range_left, (range_left + range_right) / 2, op_left, op_right, f); modifyRec(2 * range_index + 1, (range_left + range_right) / 2, range_right, 0, half, action[range_index]); modifyRec(2 * range_index + 1, (range_left + range_right) / 2, range_right, op_left, op_right, f); value[range_index] = acc(value[2 * range_index], value[2 * range_index + 1]); action[range_index] = OpMonoid::identity(); } } T accumulateRec(const int range_index, const int range_left, const int range_right, const int op_left, const int op_right) const { if (op_left <= range_left and range_right <= op_right) { return value[range_index]; } else if (range_right <= op_left or op_right <= range_left) { return AccMonoid::identity(); } else { return act(action[range_index], acc(accumulateRec(2 * range_index, range_left, (range_left + range_right) / 2, op_left, op_right), accumulateRec(2 * range_index + 1, (range_left + range_right) / 2, range_right, op_left, op_right))); } } int queryRec(const int range_index, const int range_left, const int range_right, const int op_left, const int op_right) const { if (op_left <= range_left and range_right <= op_right) { return value[range_index]; } else if (range_right <= op_left or op_right <= range_left) { return AccMonoid::identity(); } else { return queryRec(2 * range_index, range_left, (range_left + range_right) / 2, op_left, op_right) + queryRec(2 * range_index + 1, (range_left + range_right) / 2, range_right, op_left, op_right); } } const int data_num; // Num of valid data on leaves. const int size; const int half; vector<T> value; // Tree for value(length: size) vector<F> action; // Tree for action(length: half) bool has_lazy; const AccMonoid acc{}; const OpMonoid compose{}; const BaseAlgebra act{}; }; struct Min_Plus { using T = pair<ll, int>; struct AccMonoid { T operator()(const T& a, const T& b) const { return min(a, b); } static constexpr T identity() { return make_pair(INF<ll>, INF<int>); } }; struct OpMonoid { using T = ll; T operator()(const T& f1, const T& f2) const { return f1 + f2; } static constexpr T identity() { return 0; } }; T operator()(const OpMonoid::T& f, const T& x) const { return {x.first + f, x.second}; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<ll> T(N - 1); vector<ll> init(N - 1); using P = pair<ll, int>; vector<P> tim(N - 1); for (int i = 0; i < N - 1; i++) { ll prev = (i == 0 ? 0LL : init[i - 1] + 3); cin >> T[i]; tim[i].second = i; if (prev > T[i]) { tim[i].first = prev - T[i]; init[i] = prev; } else { tim[i].first = 0; init[i] = T[i]; } } int M; cin >> M; SegmentTree<Min_Plus> seg(tim); ll prev = init[N - 2] + 3; for (int i = 0; i < M; i++) { int l, r; cin >> l >> r; l--, r--; ll d; cin >> d; const P minimum = seg.accumulate(l, r + 1); if (minimum.first >= d) { seg.modify(l, r + 1, -d); cout << prev << endl; } else { const int ind = minimum.second; const ll rest = d - minimum.first; seg.modify(l, r + 1, -minimum.first); seg.modify(ind + 1, N - 1, rest); prev += rest; cout << prev << endl; } } return 0; }