Submission #245053

#TimeUsernameProblemLanguageResultExecution timeMemory
245053ld_minh4354Foehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
172 ms11640 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second #define pb push_back int n,q,s,t,a[200010],l,r,x,ans,p,i; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>q>>s>>t; for (i=0;i<n+1;i++) cin>>a[i]; for (i=n;i>0;i--) a[i]=a[i-1]-a[i]; //for (i=1;i<n+1;i++) cout<<a[i]<<" "; ans=0;for (i=1;i<n+1;i++) if (a[i]>0) ans=ans+t*(a[i]);else ans=ans+s*a[i]; //cout<<ans; for (i=1;i<q+1;i++) { cin>>l>>r>>x; p=a[l];a[l]=a[l]-x; if (p<0) { if (a[l]>0) ans=ans-p*s+a[l]*t; else ans=ans-x*s; } else { if (a[l]<0) ans=ans-p*t+a[l]*s; else ans=ans-x*t; } if (r<n) { p=a[r+1];a[r+1]=a[r+1]+x; if (p<0) { if (a[r+1]>0) ans=ans-p*s+a[r+1]*t; else ans=ans+x*s; } else { if (a[r+1]<0) ans=ans-p*t+a[r+1]*s; else ans=ans+x*t; } } cout<<ans<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...