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 <iostream>
#include <vector>
using namespace std;
int main() {
int N, Q, S, T;
cin >> N >> Q >> S >> T;
vector<int> A(N + 1);
for (int i = 0; i <= N; ++i) {
cin >> A[i];
}
int temp = 0;
for (int i = 0; i < N; ++i) {
if (A[i] < A[i + 1]) {
temp -= S * (A[i + 1] - A[i]);
} else {
temp += T * (A[i] - A[i + 1]);
}
}
for (int i = 0; i < Q; ++i) {
int L, R, X;
cin >> L >> R >> X;
if (L > 0) {
if (A[L - 1] < A[L]) temp += S * (A[L] - A[L - 1]);
else temp -= T * (A[L - 1] - A[L]);
}
if (R < N) {
if (A[R] < A[R + 1]) temp += S * (A[R + 1] - A[R]);
else temp -= T * (A[R] - A[R + 1]);
}
for (int j = L; j <= R; ++j) {
A[j] += X;
}
if (L > 0) {
if (A[L - 1] < A[L]) temp -= S * (A[L] - A[L - 1]);
else temp += T * (A[L - 1] - A[L]);
}
if (R < N) {
if (A[R] < A[R + 1]) temp -= S * (A[R + 1] - A[R]);
else temp += T * (A[R] - A[R + 1]);
}
cout << temp << endl;
}
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... |