#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 200005;
ll a[maxn], diff[maxn];
int n, q;
ll S, T;
ll cost(ll x) {
if (x > 0) return -S * x;
else return -T * x;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> q >> S >> T;
for (int i = 0; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) diff[i] = a[i] - a[i - 1];
ll ans = 0;
for (int i = 1; i <= n; i++) ans += cost(diff[i]);
while (q--) {
int L, R;
ll X;
cin >> L >> R >> X;
// Remove old contributions
ans -= cost(diff[L]);
diff[L] += X;
ans += cost(diff[L]);
if (R + 1 <= n) {
ans -= cost(diff[R + 1]);
diff[R + 1] -= X;
ans += cost(diff[R + 1]);
}
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... |