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;
const int DIM = 1000005;
long long arr[DIM], dif[DIM];
long long cost(long long val, int s, int t) {
if (val >= 0) {
return -val * s; }
else {
return -val * t; } }
int main(void) {
#ifdef HOME
freopen("phenomena.in", "r", stdin);
freopen("phenomena.out", "w", stdout);
#endif
int n, q, s, t; cin >> n >> q >> s >> t;
long long ans = 0;
for (int i = 0; i <= n; ++i) {
cin >> arr[i];
if (i >= 1) {
dif[i] = arr[i] - arr[i - 1];
ans += cost(dif[i], s, t); } }
while (q--) {
int l, r, x;
cin >> l >> r >> x;
ans -= cost(dif[l], s, t);
dif[l] += x; ans += cost(dif[l], s, t);
if (r < n) {
ans -= cost(dif[r + 1], s, t);
dif[r + 1] -= x; ans += cost(dif[r + 1], s, 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... |