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;
long long a[200005], diff[200005];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, q, s, t, pre, ans=0;
cin >> n >> q >> s >> t >> pre;
for (long long i=1; i<=n; i++)
{
long long x;
cin >> x;
diff[i]=x-pre;
pre=x;
if (diff[i]>=0)
ans-=diff[i]*s;
else
ans-=diff[i]*t;
}
for (long long i=1; i<=q; i++)
{
long long l, r, x;
cin >> l >> r >> x;
if (diff[l]>=0)
ans+=diff[l]*s;
else
ans+=diff[l]*t;
diff[l]+=x;
if (diff[l]>=0)
ans-=diff[l]*s;
else
ans-=diff[l]*t;
if (r<n)
{
if (diff[r+1]>=0)
ans+=diff[r+1]*s;
else
ans+=diff[r+1]*t;
diff[r+1]-=x;
if (diff[r+1]>=0)
ans-=diff[r+1]*s;
else
ans-=diff[r+1]*t;
}
cout << ans << '\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... |