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>
#define int long long
using namespace std;
void solve()
{
int n, q, a, b;
cin >> n >> q >> a >> b;
vector<int> v(n + 1);
for (int &i : v)
cin >> i;
int ans = 0;
vector<int> dif(n);
for (int i = 0; i < n; ++i)
{
dif[i] = v[i + 1] - v[i];
if (dif[i] >= 0)
ans -= a * dif[i];
else
ans -= b * dif[i];
}
while (q--)
{
int l, r, k;
cin >> l >> r >> k;
--l;
if (dif[l] >= 0)
ans += a * dif[l];
else
ans += b * dif[l];
dif[l] += k;
if (dif[l] >= 0)
ans -= a * dif[l];
else
ans -= b * dif[l];
if (r < n)
{
if (dif[r] >= 0)
ans += a * dif[r];
else
ans += b * dif[r];
dif[r] -= k;
if (dif[r] >= 0)
ans -= a * dif[r];
else
ans -= b * dif[r];
}
cout << ans << '\n';
}
}
/*
3 5 1 2
0 4 1 8
1 2 2
1 1 -2
2 3 5
1 2 -1
1 3 5
*/
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
solve();
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... |