Submission #701419

#TimeUsernameProblemLanguageResultExecution timeMemory
701419happypotatoFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
490 ms13172 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll n, q, s, t; cin >> n >> q >> s >> t; ll a[n + 1]; for (int i = 0; i <= n; i++) cin >> a[i]; ll ans = 0; ll diff[n + 1]; for (int i = 1; i <= n; i++) { diff[i] = a[i] - a[i - 1]; if (diff[i] > 0) ans -= s * diff[i]; else ans += t * -diff[i]; } while (q--) { int l, r, k; cin >> l >> r >> k; if (l >= 1) { if (diff[l] > 0) ans += s * diff[l]; else ans -= t * -diff[l]; diff[l] += k; if (diff[l] > 0) ans -= s * diff[l]; else ans += t * -diff[l]; } if (r < n) { if (diff[r + 1] > 0) ans += s * diff[r + 1]; else ans -= t * -diff[r + 1]; diff[r + 1] -= k; if (diff[r + 1] > 0) ans -= s * diff[r + 1]; else ans += t * -diff[r + 1]; } cout << ans << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...