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 main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q, s, t;
cin >> n >> q >> s >> t;
auto newVal = [&](long long x) {
if (x < 0) {
return x * s;
} else {
return x * t;
}
};
vector<int> a(n + 1);
for (int i = 0; i <= n; i++) {
cin >> a[i];
}
vector<long long> b(n + 1);
long long ans = 0ll;
for (int i = 1; i <= n; i++) {
b[i] = a[i - 1] - a[i];
if (b[i] < 0) {
ans += b[i] * s;
} else {
ans += b[i] * t;
}
}
while (q--) {
int l, r, x;
cin >> l >> r >> x;
if (l > 0) {
ans -= newVal(b[l]);
b[l] -= x;
ans += newVal(b[l]);
}
if (r < n) {
ans -= newVal(b[r + 1]);
b[r + 1] += x;
ans += newVal(b[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... |