Submission #749913

#TimeUsernameProblemLanguageResultExecution timeMemory
749913pccFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
126 ms11596 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const ll mxn = 2e5+10; int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); ll n,q; cin>>n>>q; ll S,T; cin>>S>>T; ll arr[n+1]; ll ans = 0; for(int i = 0;i<=n;i++)cin>>arr[i]; for(int i = 1;i<=n;i++){ if(arr[i]>arr[i-1])ans -= S*(arr[i]-arr[i-1]); else ans += T*(arr[i-1]-arr[i]); } for(int i = n;i>=1;i--){ arr[i] = arr[i]-arr[i-1]; } while(q--){ ll l,r,k; cin>>l>>r>>k; if(arr[l]<0)ans -= abs(arr[l])*T; else ans += abs(arr[l])*S; arr[l] += k; if(arr[l]<0)ans += abs(arr[l])*T; else ans -= abs(arr[l])*S; l = r+1; if(l>n){ cout<<ans<<'\n'; continue; } if(arr[l]<0)ans -= abs(arr[l])*T; else ans += abs(arr[l])*S; arr[l] -= k; if(arr[l]<0)ans += abs(arr[l])*T; else ans -= abs(arr[l])*S; cout<<ans<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...