This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N=200007;
int n,q,l,r;
long long a[N],v,up,down,ans=0,dif[N];
int main(){
cin>>n>>q>>up>>down;
cin>>a[0];
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=0;i<n;i++){
if(a[i]<a[i+1]) ans-=up*abs(a[i]-a[i+1]);
else ans+=down*abs(a[i]-a[i+1]);
}
for(int i=0;i<n;i++){
dif[i]=a[i]-a[i+1];
}
while(q--){
cin>>l>>r>>v;
long long old=dif[l-1];
dif[l-1]-=v;
if(old<0) ans+=up*(-old);
else ans-=down*old;
if(dif[l-1]<0) ans-=up*(-dif[l-1]);
else ans+=down*dif[l-1];
if(r<n){
old=dif[r];
dif[r]+=v;
if(old<0) ans+=up*(-old);
else ans-=down*old;
if(dif[r]<0) ans-=up*(-dif[r]);
else ans+=down*dif[r];
}
printf("%lld\n",ans);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |