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 <iostream>
using namespace std;
#define ll long long
ll arr[200001], diff[200001];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, q; ll s, t;
cin >> n >> q >> s >> t;
for(int i = 0; i <= n; i++)
cin >> arr[i];
ll neg = 0, pos = 0;
for(int i = 0; i < n; i++)
{
diff[i] = arr[i]-arr[i+1];
if(diff[i] < 0)
neg -= diff[i];
else
pos += diff[i];
}
while(q--)
{
int l, r; ll d;
cin >> l >> r >> d;
if(diff[l-1] < 0)
neg += diff[l-1];
else
pos -= diff[l-1];
if(r < n && diff[r] < 0)
neg += diff[r];
else if(r < n)
pos -= diff[r];
diff[l-1] -= d;
diff[r] += d;
if(diff[l-1] < 0)
neg -= diff[l-1];
else
pos += diff[l-1];
if(r < n && diff[r] < 0)
neg -= diff[r];
else if(r < n)
pos += diff[r];
cout << -neg*s + pos*t << '\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... |