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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int N, Q, S, T; cin >> N >> Q >> S >> T;
vector<int> A(N + 1), dif(N);
for (int i = 0; i <= N; ++i) {
cin >> A[i];
}
long long res = 0;
for (int i = 0; i < N; ++i) {
dif[i] = A[i] - A[i + 1];
res += (long long) abs(dif[i]) * (dif[i] >= 0 ? T : -S);
}
auto upd = [&](int i, int x) {
res -= (long long) abs(dif[i]) * (dif[i] >= 0 ? T : -S);
dif[i] += x;
res += (long long) abs(dif[i]) * (dif[i] >= 0 ? T : -S);
};
while (Q--) {
int l, r, x; cin >> l >> r >> x;
upd(l - 1, -x);
if (r < N) {
upd(r, x);
}
cout << res << "\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... |