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()
{
int n,q,s,t;
cin>>n>>q>>s>>t;
int result = 0;
int a[n+1];
int b[n+1];
a[0] = 0;
for(int i=0;i<=n;i++)
cin>>a[i];
for(int 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(int i=0;i<q;i++)
{
int 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... |