Submission #837572

#TimeUsernameProblemLanguageResultExecution timeMemory
837572borisAngelovFoehn Phenomena (JOI17_foehn_phenomena)C++17
30 / 100
10 ms1236 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n, q; long long s, t; int a[maxn]; long long delta[maxn]; struct state { long long positive_sum; // multiply by s long long negative_sum; // multiply by t }; struct segment_tree { state tree[4 * maxn]; state combine(const state left_child, const state right_child) { state result; result.positive_sum = left_child.positive_sum + right_child.positive_sum; result.negative_sum = left_child.negative_sum + right_child.negative_sum; return result; } void build(int node, int l, int r) { if (l == r) { if (delta[l] < 0) { tree[node].negative_sum = delta[l]; tree[node].positive_sum = 0; } else { tree[node].positive_sum = delta[l]; tree[node].negative_sum = 0; } return; } int mid = (l + r) / 2; build(2 * node, l, mid); build(2 * node + 1, mid + 1, r); tree[node] = combine(tree[2 * node], tree[2 * node + 1]); } void update(int node, int l, int r, int pos, long long val) { if (l == r) { if (val < 0) { tree[node].negative_sum = val; tree[node].positive_sum = 0; } else { tree[node].positive_sum = val; tree[node].negative_sum = 0; } return; } int mid = (l + r) / 2; if (pos <= mid) { update(2 * node, l, mid, pos, val); } else { update(2 * node + 1, mid + 1, r, pos, val); } tree[node] = combine(tree[2 * node], tree[2 * node + 1]); } void build() { build(1, 1, n); } void update(int pos, long long val) { update(1, 1, n, pos, val); } }; segment_tree tree; void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fastIO(); cin >> n >> q >> s >> t; for (int i = 1; i <= n + 1; ++i) { cin >> a[i]; } for (int i = 1; i <= n; ++i) { delta[i] = a[i] - a[i + 1]; } tree.build(); for (int i = 1; i <= q; ++i) { int l, r, val; cin >> l >> r >> val; if (l != 0) { delta[l] -= val; tree.update(l, delta[l]); } if (r != n) { delta[r + 1] += val; tree.update(r + 1, delta[r + 1]); } cout << tree.tree[1].negative_sum * s + tree.tree[1].positive_sum * t << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...