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