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 n, q, s, t, a[200005], l, r, x, dif[200005], sumpos, sumneg;
int main() {
cin >> n >> q >> s >> t;
for (int i = 0; i <= n; i++) {
cin >> a[i];
if (i == 0) dif[0] = a[i];
else dif[i] = a[i]-a[i-1];
if (dif[i] > 0) sumpos += dif[i];
else sumneg += dif[i];
}
// for (int i = 0; i <= n; i++) {
// cout << dif[i] << " ";
// }
// cout << endl;
// cout << sumpos << " " << sumneg << endl;
for(int i = 0; i < q; i++) {
cin >> l >> r >> x;
if (dif[l] > 0) sumpos -= dif[l];
else sumneg -= dif[l];
dif[l] += x;
if (dif[l] > 0) sumpos += dif[l];
else sumneg += dif[l];
if (r != n) {
if (dif[r+1] > 0) sumpos -= dif[r+1];
else sumneg -= dif[r+1];
dif[r+1] -= x;
if (dif[r+1] > 0) sumpos += dif[r+1];
else sumneg += dif[r+1];
}
// for (int i = 0; i <= n; i++) {
// cout << dif[i] << " ";
// }
// cout << endl;
// cout << sumpos << " " << sumneg << endl;
cout << -(sumpos*s + sumneg*t) << 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... |