Submission #129299

#TimeUsernameProblemLanguageResultExecution timeMemory
129299nhimnam120Foehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
674 ms7416 KiB
#include<bits/stdc++.h> using namespace std; const long long N=2e5+5; long long alt[N]; long long diff[N]; long long n,q,s,t; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> q >> s >> t; long long ans=0; for(int i=0;i<=n;i++){ cin >> alt[i]; if(i>=1){ diff[i] = alt[i] - alt[i-1]; if(diff[i]>0){ ans = ans - diff[i]*s; } else{ ans = ans - diff[i]*t; } } } while(q--){ long long l, r, x; cin >> l >> r >> x; if(l>=1&&l<=n){ if(diff[l]>0){ ans = ans + diff[l]*s; } else{ ans = ans + diff[l]*t; } } if(r+1<=n&&r+1>=1){ if(diff[r+1]>0){ ans = ans + diff[r+1]*s; } else{ ans = ans + diff[r+1]*t; } } diff[l]+=x; diff[r+1]-=x; if(l>=1&&l<=n){ if(diff[l]>0){ ans = ans - diff[l]*s; } else{ ans = ans - diff[l]*t; } } if(r+1<=n&&r+1>=1){ if(diff[r+1]>0){ ans = ans - diff[r+1]*s; } else{ ans = ans - diff[r+1]*t; } } cout << ans<<endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...