Submission #773282

#TimeUsernameProblemLanguageResultExecution timeMemory
773282kirakaminski968Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
103 ms13144 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N,Q; ll S,T; cin >> N >> Q >> S >> T; vector<ll> arr(N+1); for(int i = 0;i<=N;++i) cin >> arr[i]; vector<ll> diff(N); for(int i = 0;i<N;++i) diff[i] = arr[i]-arr[i+1]; ll ans = 0; for(int i = 0;i<N;++i){ if(diff[i] < 0) ans += S*diff[i]; else ans += T*diff[i]; } //cout << ans << "\n"; while(Q--){ int l,r; ll val; cin >> l >> r >> val; ll x; if(diff[l-1] < 0) x = S*diff[l-1]; else x = T*diff[l-1]; ans -= x; diff[l-1] -= val; if(diff[l-1] < 0) x = S*diff[l-1]; else x = T*diff[l-1]; ans += x; if(r < N){ if(diff[r] < 0) x = S*diff[r]; else x = T*diff[r]; ans -= x; diff[r] += val; if(diff[r] < 0) x = S*diff[r]; else x = T*diff[r]; ans += x; } cout << ans << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...