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>
#include <algorithm>
#include <stack>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
ll h[N], a[N];
int main() {
ll n, q, s, t;
cin >> n >> q >> s >> t;
for (int i = 0; i <= n; i++) {
cin >> h[i];
}
ll cur_s = 0, cur_t = 0;
for (int i = 1; i <= n; i++) {
a[i] = h[i] - h[i - 1];
if (a[i] > 0) cur_s += a[i];
else cur_t += (-a[i]);
}
while (q--) {
ll l, r, x;
cin >> l >> r >> x;
if (a[l] > 0) cur_s -= a[l];
else cur_t -= (-a[l]);
a[l] += x;
if (a[l] > 0) cur_s += a[l];
else cur_t += (-a[l]);
if (r != n) {
if (a[r + 1] > 0) cur_s -= a[r + 1];
else cur_t -= (-a[r + 1]);
a[r + 1] -= x;
if (a[r + 1] > 0) cur_s += a[r + 1];
else cur_t += (-a[r + 1]);
}
cout << cur_t * 1ll * t - cur_s * 1ll * s << "\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... |