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 MAXN=200200;
long long n,q,s,t,d[MAXN]={},a[MAXN]={},ans=0;
void output();
void input()
{
cin>>n>>q>>s>>t;
for (int i=0;i<=n;i++)
cin>>a[i];
for (int i=1;i<=n;i++)
{
d[i]=a[i]-a[i-1];
if (d[i]>0)
ans-=d[i]*s;
else ans-=d[i]*t;
}
}
void process(long long l,long long r,long long v)
{
long long ndl=d[l]+v,ndr=d[r]-v;
if (d[l]<0 && ndl<0) ans+=(d[l]-ndl)*t;
if (d[l]<0 && ndl>0) ans=ans-ndl*s+d[l]*t;
if (d[l]>0 && ndl<0) ans=ans-ndl*t+d[l]*s;
if (d[l]>0 && ndl>0) ans+=(d[l]-ndl)*s;
if (r<=n)
{
if (d[r]<0 && ndr<0) ans+=(d[r]-ndr)*t;
if (d[r]<0 && ndr>0) ans=ans-ndr*s+d[r]*t;
if (d[r]>0 && ndr<0) ans=ans-ndr*t+d[r]*s;
if (d[r]>0 && ndr>0) ans+=(d[r]-ndr)*s;
}
d[l]+=v;
d[r]-=v;
}
void output()
{
cout<<ans<<endl;
}
int main()
{
int x,y,v;
input();
for (int i=1;i<=q;i++)
{
cin>>x>>y>>v;
process(x,y+1,v);
output();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |