Submission #51905

#TimeUsernameProblemLanguageResultExecution timeMemory
51905WLZFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
224 ms168964 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q, s, t; cin >> n >> q >> s >> t; auto newVal = [&](long long x) { if (x < 0) { return x * s; } else { return x * t; } }; vector<int> a(n + 1); for (int i = 0; i <= n; i++) { cin >> a[i]; } vector<long long> b(n + 1); long long ans = 0ll; for (int i = 1; i <= n; i++) { b[i] = a[i - 1] - a[i]; if (b[i] < 0) { ans += b[i] * s; } else { ans += b[i] * t; } } while (q--) { int l, r, x; cin >> l >> r >> x; if (l > 0) { ans -= newVal(b[l]); b[l] -= x; ans += newVal(b[l]); } if (r < n) { ans -= newVal(b[r + 1]); b[r + 1] += x; ans += newVal(b[r + 1]); } cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...