Submission #939110

#TimeUsernameProblemLanguageResultExecution timeMemory
939110qwe1rt1yuiop1Foehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
98 ms13268 KiB
#include <bits/stdc++.h> #define int long long using namespace std; void solve() { int n, q, a, b; cin >> n >> q >> a >> b; vector<int> v(n + 1); for (int &i : v) cin >> i; int ans = 0; vector<int> dif(n); for (int i = 0; i < n; ++i) { dif[i] = v[i + 1] - v[i]; if (dif[i] >= 0) ans -= a * dif[i]; else ans -= b * dif[i]; } while (q--) { int l, r, k; cin >> l >> r >> k; --l; if (dif[l] >= 0) ans += a * dif[l]; else ans += b * dif[l]; dif[l] += k; if (dif[l] >= 0) ans -= a * dif[l]; else ans -= b * dif[l]; if (r < n) { if (dif[r] >= 0) ans += a * dif[r]; else ans += b * dif[r]; dif[r] -= k; if (dif[r] >= 0) ans -= a * dif[r]; else ans -= b * dif[r]; } cout << ans << '\n'; } } /* 3 5 1 2 0 4 1 8 1 2 2 1 1 -2 2 3 5 1 2 -1 1 3 5 */ signed main() { ios::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...