Submission #305795

#TimeUsernameProblemLanguageResultExecution timeMemory
305795couplefireFoehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
565 ms7416 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 300005 long long dif[MAXN]; long long arr[MAXN]; long long n, q, s, t; int main(){ // freopen("a.in", "r", stdin); ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> q >> s >> t; t = -t; dif[0] = 0; for(long long i = 0; i<=n; i++){ long long a; cin >> a; arr[i] = a; if(i >= 1) dif[i] = a-arr[i-1]; } // for(long long i = 1; i<=n; i++){ // cout << dif[i] << " "; // } // cout << endl; long long ans = 0; for(long long i = 1; i<=n; i++){ if(dif[i]>0) ans -= s*dif[i]; else ans += t*dif[i]; } // cout << ans << endl; while(q--){ long long l, r, x; cin >> l >> r >> x; long long curl = dif[l]; dif[l]+=x; if(curl > 0) ans += s*curl; else ans -= t*curl; if(dif[l]>0) ans -= s*dif[l]; else ans += t*dif[l]; if(r == n){ cout << ans << endl; continue; } long long curr = dif[r+1]; dif[r+1] -= x; if(curr > 0) ans += s*curr; else ans -= t*curr; if(dif[r+1] > 0) ans -= s*dif[r+1]; else ans += t*dif[r+1]; cout << ans << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...