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>
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |