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;
int a[200005];
long long c[200005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, q, s, t;
cin >> n >> q >> s >> t;
for (int i = 0; i <= n; ++i) {
cin >> a[i];
}
long long ans = 0;
for (int i = 1; i <= n; ++i) {
c[i] = a[i - 1] - a[i];
if (c[i] < 0) {
ans += 1ll * c[i] * s;
} else {
ans += 1ll * c[i] * t;
}
}
while (q--) {
int l, r, x;
cin >> l >> r >> x;
if (c[l] < 0) {
ans -= 1ll * c[l] * s;
} else {
ans -= 1ll * c[l] * t;
}
if (r + 1 <= n) {
if (c[r + 1] < 0) {
ans -= 1ll * c[r + 1] * s;
} else {
ans -= 1ll * c[r + 1] * t;
}
}
c[l] -= x;
if (r + 1 <= n) {
c[r + 1] += x;
}
if (c[l] < 0) {
ans += 1ll * c[l] * s;
} else {
ans += 1ll * c[l] * t;
}
if (r + 1 <= n) {
if (c[r + 1] < 0) {
ans += 1ll * c[r + 1] * s;
} else {
ans += 1ll * c[r + 1] * t;
}
}
cout << ans << '\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... |