Submission #367641

#TimeUsernameProblemLanguageResultExecution timeMemory
367641shafinalamFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
787 ms13172 KiB
#include "bits/stdc++.h" using namespace std; typedef long long ll; const int mxn = 2e5+5; ll arr[mxn]; ll diff[mxn]; int main() { ll n, q, S, T; cin >> n >> q >> S >> T; for(int i = 0; i <= n; i++) { cin >> arr[i]; } ll ans = 0; for(int i = 1; i <= n; i++) { ll d = arr[i]-arr[i-1]; diff[i] = d; if(d>0) { ans-=(abs(d)*S); } else { ans+=(abs(d)*T); } //cout << ans << '\n'; } //cout << ans << '\n'; while(q--) { ll l, r, x; cin >> l >> r >> x; if(diff[l]>0) ans += (abs(diff[l])*S); else ans -= (abs(diff[l])*T); diff[l]+=x; if(diff[l]>0) ans -= (abs(diff[l])*S); else ans += (abs(diff[l])*T); if(r+1<=n) { if(diff[r+1]>0) ans += (abs(diff[r+1])*S); else ans -= (abs(diff[r+1])*T); diff[r+1]-=x; if(diff[r+1]>0) ans -= (abs(diff[r+1])*S); else ans += (abs(diff[r+1])*T); } cout << ans << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...