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;
typedef long long ll;
ll n, q, s, t;
ll a[200020], l[200020], r[200020], x[200020], diff[200020];
int 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];
diff[i]=a[i]-a[max(i-1, 0)];
}
for(int i=0; i<q; i++)cin>>l[i]>>r[i]>>x[i];
ll windspid=0;
for(int i=1; i<=n; i++)
{
if(diff[i]>0)windspid-=s*diff[i];
else windspid-=t*diff[i];
}
for(int i=0; i<q; i++)
{
if(diff[l[i]]>0)windspid+=s*diff[l[i]];
else windspid+=t*diff[l[i]];
diff[l[i]]+=x[i];
if(diff[l[i]]>0)windspid-=s*diff[l[i]];
else windspid-=t*diff[l[i]];
if(r[i]<n)
{
if(diff[r[i]+1]>0)windspid+=s*diff[r[i]+1];
else windspid+=t*diff[r[i]+1];
diff[r[i]+1]-=x[i];
if(diff[r[i]+1]>0)windspid-=s*diff[r[i]+1];
else windspid-=t*diff[r[i]+1];
}
cout<<windspid<<"\n";
}
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... |