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 ll long long
#define endl "\n"
using namespace std;
void solve()
{
ll n, q, s, t;
cin >> n >> q >> s >> t;
ll a[n + 1], b[n];
for (ll &i : a)
cin >> i;
ll ans = 0;
for (ll i = 1; i <= n; i++)
b[i] = a[i] - a[i - 1], ans -= (b[i] < 0 ? b[i] * t : b[i] * s);
while (q--)
{
ll l, r, x;
cin >> l >> r >> x;
ans += (b[l] < 0 ? b[l] * t : b[l] * s);
if (r + 1 <= n)
ans += (b[r + 1] < 0 ? b[r + 1] * t : b[r + 1] * s);
b[l] += x;
if (r + 1 <= n)
b[r + 1] -= x;
ans -= (b[l] < 0 ? b[l] * t : b[l] * s);
if (r + 1 <= n)
ans -= (b[r + 1] < 0 ? b[r + 1] * t : b[r + 1] * s);
cout << ans << endl;
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
ll t = 1;
// precomp();
// cin >> t;
for (ll i = 1; i <= t; i++)
solve();
cerr << "\nTime elapsed: " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\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... |