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;
signed main()
{
long long n,q,s,t;
cin>>n>>q>>s>>t;
long long result = 0;
long long a[n+1];
long long b[n+1];
a[0] = 0;
for(long long i=0;i<=n;i++)
cin>>a[i];
for(long long i=1;i<=n;i++)
{
b[i] = a[i-1] - a[i];
if(b[i]<0)
result += b[i]*s;
else
result += b[i]*t;
}
for(long long i=0;i<q;i++)
{
long long l,r,x;
cin>>l>>r>>x;
if(l)
{
if(b[l]<0)
result -= b[l]*s;
else
result -= b[l]*t;
b[l] -= x;
if(b[l]<0)
result += b[l]*s;
else
result += b[l]*t;
}
if(r<n)
{
if(b[r+1]<0)
result -= b[r+1]*s;
else
result -= b[r+1]*t;
b[r+1] += x;
if(b[r+1]<0)
result += b[r+1]*s;
else
result += b[r+1]*t;
}
cout<<result<<'\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... |