Submission #751116

#TimeUsernameProblemLanguageResultExecution timeMemory
751116vjudge1Foehn Phenomena (JOI17_foehn_phenomena)C++17
10 / 100
114 ms5580 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, q, s, t; cin >> n >> q >> s >> t; vector<ll> h(n + 1); ll hDiff = 0; for (int i = 0; i <= n; i++) { cin >> h[i]; if (i > 0) { if (h[i - 1] < h[i]) { hDiff += (h[i - 1] - h[i]) * s; } else { hDiff += (h[i - 1] - h[i]) * t; } } } ll l, r, x; for (int i = 0; i < q; i++) { cin >> l >> r >> x; ll ans = hDiff; if (l > 0) { // cout << "1 : " << ans; if (h[l - 1] < (h[l])) { ans -= (h[l - 1] - (h[l])) * s; } else { ans -= (h[l - 1] - (h[l])) * t; } // cout << " 2: " << ans; h[l] += x; if (h[l - 1] < (h[l])) { ans += (h[l - 1] - (h[l])) * s; } else { ans += ((h[l - 1] - (h[l]))) * t; } // cout << " 3: " << ans; h[l] -= x; } if (r < n) { // cout << " 4 : " << ans; if (h[r] < (h[r + 1])) { ans -= ((h[r]) - (h[r + 1])) * s; } else { ans -= ((h[r]) - (h[r + 1])) * t; } // cout << " 5: " << ans; h[r] += x; if (h[r] < (h[r + 1])) { ans += ((h[r]) - (h[r + 1])) * s; } else { ans += ((h[r]) - (h[r + 1])) * t; } // cout << " 6: " << ans; h[r] -= x; } if (r != l) { h[r] += x; } h[l] += x; hDiff = ans; cout << ans << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...