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() {
ll n, q, s, t;
cin >> n >> q >> s >> t;
ll a[n + 1];
for (int i = 0; i <= n; i++) cin >> a[i];
ll ans = 0;
ll diff[n + 1];
for (int i = 1; i <= n; i++) {
diff[i] = a[i] - a[i - 1];
if (diff[i] > 0) ans -= s * diff[i];
else ans += t * -diff[i];
}
while (q--) {
int l, r, k;
cin >> l >> r >> k;
if (l >= 1) {
if (diff[l] > 0) ans += s * diff[l];
else ans -= t * -diff[l];
diff[l] += k;
if (diff[l] > 0) ans -= s * diff[l];
else ans += t * -diff[l];
}
if (r < n) {
if (diff[r + 1] > 0) ans += s * diff[r + 1];
else ans -= t * -diff[r + 1];
diff[r + 1] -= k;
if (diff[r + 1] > 0) ans -= s * diff[r + 1];
else ans += t * -diff[r + 1];
}
cout << ans << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |