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;
typedef long long ll;
const int MX = 2e5 + 5;
ll a[MX], d[MX];
ll N, Q, S, T;
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> N >> Q >> S >> T;
ll ans = 0;
S = -S;
for(int i = 0; i <= N; i++) {
cin >> a[i];
if(!i) continue;
d[i] = a[i] - a[i - 1];
if(d[i] > 0) ans += d[i] * S;
if(d[i] < 0) ans += -d[i] * T;
}
for(int j = 1; j <= Q; j++) {
ll L, R, X;
cin >> L >> R >> X;
if(d[L] > 0) ans -= d[L] * S;
if(d[L] < 0) ans -= -d[L] * T;
d[L] += X;
if(d[L] > 0) ans += d[L] * S;
if(d[L] < 0) ans += -d[L] * T;
if(R + 1 <= N) {
if(d[R + 1] > 0) ans -= d[R + 1] * S;
if(d[R + 1] < 0) ans -= -d[R + 1] * T;
d[R + 1] -= X;
if(d[R + 1] > 0) ans += d[R + 1] * S;
if(d[R + 1] < 0) ans += -d[R + 1] * T;
}
cout << ans << '\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... |