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_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, q, s, t;
cin >> n >> q >> s >> t;
vector<int> A(n + 1);
for (int &a : A) {
cin >> a;
}
vector<int64_t> deltas(n);
int64_t non_neg_deltas = 0, neg_deltas = 0;
auto upd_deltas = [&](int i, int64_t by_val) {
if (i >= n) { return; }
(deltas[i] < 0 ? neg_deltas : non_neg_deltas) -= deltas[i];
deltas[i] += by_val;
(deltas[i] < 0 ? neg_deltas : non_neg_deltas) += deltas[i];
};
for (int i = 0; i < n; ++i) {
upd_deltas(i, A[i] - A[i + 1]);
}
for (int i = 0; i < q; ++i) {
int l, r, x;
cin >> l >> r >> x;
upd_deltas(l - 1, -x);
upd_deltas(r, x);
cout << s * neg_deltas + t * non_neg_deltas << '\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... |