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 main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, q, s, t;
cin >> n >> q >> s >> t;
vector<int> a(n + 1);
for (int i = 0; i <= n; i++) {
cin >> a[i];
}
vector<long long> diff(n);
long long ans = 0;
for (int i = 0; i < n; i++) {
diff[i] = a[i + 1] - a[i];
ans += (diff[i] > 0 ? diff[i] * -s : diff[i] * -t);
}
auto update = [&](int i, int v) -> void {
ans -= (diff[i] > 0 ? diff[i] * -s : diff[i] * -t);
diff[i] += v;
ans += (diff[i] > 0 ? diff[i] * -s : diff[i] * -t);
};
while (q--) {
int l, r, x;
cin >> l >> r >> x;
update(l - 1, x);
if (r < n) {
update(r, -x);
}
cout << ans << '\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... |