Submission #1019982

#TimeUsernameProblemLanguageResultExecution timeMemory
1019982vjudge1Foehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
87 ms12372 KiB
#include <bits/stdc++.h> using namespace std; int a[200005]; long long c[200005]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, q, s, t; cin >> n >> q >> s >> t; for (int i = 0; i <= n; ++i) { cin >> a[i]; } long long ans = 0; for (int i = 1; i <= n; ++i) { c[i] = a[i - 1] - a[i]; if (c[i] < 0) { ans += 1ll * c[i] * s; } else { ans += 1ll * c[i] * t; } } while (q--) { int l, r, x; cin >> l >> r >> x; if (c[l] < 0) { ans -= 1ll * c[l] * s; } else { ans -= 1ll * c[l] * t; } if (r + 1 <= n) { if (c[r + 1] < 0) { ans -= 1ll * c[r + 1] * s; } else { ans -= 1ll * c[r + 1] * t; } } c[l] -= x; if (r + 1 <= n) { c[r + 1] += x; } if (c[l] < 0) { ans += 1ll * c[l] * s; } else { ans += 1ll * c[l] * t; } if (r + 1 <= n) { if (c[r + 1] < 0) { ans += 1ll * c[r + 1] * s; } else { ans += 1ll * c[r + 1] * t; } } cout << ans << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...