Submission #1112786

#TimeUsernameProblemLanguageResultExecution timeMemory
1112786sunboiFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
524 ms13248 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n, q, s, t; cin >> n >> q >> s >> t; vector<int> a(n + 1), dif(n + 1); for (int i = 0; i <= n; i++){ cin >> a[i]; } int ans = 0; for (int i = 1; i <= n; i++){ dif[i] = a[i] - a[i - 1]; if (dif[i] > 0) ans += -1 * s * dif[i]; else ans += t * abs(dif[i]); } while(q--){ int l, r, x; cin >> l >> r >> x; if (dif[l] > 0) ans -= -1 * s * dif[l]; else ans -= t * abs(dif[l]); dif[l] += x; if (dif[l] > 0) ans += -1 * s * dif[l]; else ans += t * abs(dif[l]); if (r < n){ r++; if (dif[r] > 0) ans -= -1 * s * dif[r]; else ans -= t * abs(dif[r]); dif[r] -= x; if (dif[r] > 0) ans += -1 * s * dif[r]; else ans += t * abs(dif[r]); } cout << ans << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...