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;
using ll = long long;
const int N = 2e5 + 5;
int n, q;
ll s, t;
int a[N];
ll d[N];
ll decr, incr;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q >> s >> t;
s = -s;
for (int i = 0; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
d[i] = a[i] - a[i - 1];
if (d[i] > 0)
decr += d[i];
else
incr += abs(d[i]);
}
while (q--) {
int l, r, x;
cin >> l >> r >> x;
if (d[l] > 0)
decr -= d[l];
else
incr -= abs(d[l]);
d[l] += x;
if (d[l] > 0)
decr += d[l];
else
incr += abs(d[l]);
if (r + 1 <= n) {
if (d[r + 1] > 0)
decr -= d[r + 1];
else
incr -= abs(d[r + 1]);
d[r + 1] -= x;
if (d[r + 1] > 0)
decr += d[r + 1];
else
incr += abs(d[r + 1]);
}
cout << decr * s + incr * t << '\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... |