제출 #129301

#제출 시각아이디문제언어결과실행 시간메모리
129301TienDungzFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
159 ms7288 KiB
#include<bits/stdc++.h> #define int long long using namespace std; int n,q,s,t,a[200005],dp[200005],sum=0,l,r,val; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>q>>s>>t; for(int i=0;i<=n;i++) { cin>>a[i]; if(i>=1) { dp[i]=a[i]-a[i-1]; if(dp[i]>0) sum=sum-s*dp[i]; else sum=sum-t*dp[i]; } } // cout<<sum<<"\n\n"; while(q--) { cin>>l>>r>>val; if(l>=1) { if(dp[l]>0) sum=sum+s*dp[l]; else sum=sum+t*dp[l]; dp[l]=dp[l]+val; if(dp[l]>0) sum=sum-s*dp[l]; else sum=sum-t*dp[l]; } if(r<n) { if(dp[r+1]>0) sum=sum+s*dp[r+1]; else sum=sum+t*dp[r+1]; dp[r+1]=dp[r+1]-val; if(dp[r+1]>0) sum=sum-s*dp[r+1]; else sum=sum-t*dp[r+1]; } cout<<sum<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...