Submission #895421

#TimeUsernameProblemLanguageResultExecution timeMemory
895421Richw818Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
87 ms12444 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, q, s, t; cin >> n >> q >> s >> t; vector<int> a(n + 1); for (int i = 0; i <= n; i++) { cin >> a[i]; } vector<long long> diff(n); long long ans = 0; for (int i = 0; i < n; i++) { diff[i] = a[i + 1] - a[i]; ans += (diff[i] > 0 ? diff[i] * -s : diff[i] * -t); } auto update = [&](int i, int v) -> void { ans -= (diff[i] > 0 ? diff[i] * -s : diff[i] * -t); diff[i] += v; ans += (diff[i] > 0 ? diff[i] * -s : diff[i] * -t); }; while (q--) { int l, r, x; cin >> l >> r >> x; update(l - 1, x); if (r < n) { update(r, -x); } cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...