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;
#define ll long long
#define int long long
int32_t main() {
int n, q, s, t; cin >> n >> q >> s >> t;
vector<int> altitudes(n + 1), diffs(n);
for (int i=0;i<n+1;i++) {
cin >> altitudes[i];
}
ll ans = 0;
for (int i=0;i<n;i++) {
diffs[i] = altitudes[i+1] - altitudes[i];
if (diffs[i] < 0) {
ans -= t * diffs[i];
} else {
ans -= s * diffs[i];
}
}
int a, b, c;
for (int i=0;i<q;i++) {
cin >> a >> b >> c;
if (diffs[a - 1] > 0) {
ans += s * diffs[a - 1];
} else {
ans += t * diffs[a - 1];
}
diffs[a - 1] += c;
if (diffs[a - 1] > 0) {
ans -= s * diffs[a - 1];
} else {
ans -= t * diffs[a - 1];
}
if (b != n) {
if (diffs[b] > 0) {
ans += s * diffs[b];
} else {
ans += t * diffs[b];
}
diffs[b] -= c;
if (diffs[b] > 0) {
ans -= s * diffs[b];
} else {
ans -= t * diffs[b];
}
}
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... |