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;
const int N = 2e5 + 5;
int n, m, s, t;
long long ans = 0, a[N];
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> m >> t >> s;
for(int i = 0; i <= n; ++i) cin >> a[i];
for(int i = n; i >= 1; --i) {
a[i] -= a[i - 1];
if(a[i] > 0) ans -= a[i] * t;
else ans += -a[i] * s;
}
for(int i = 0; i < m; ++i) {
int l, r, x; cin >> l >> r >> x;
if(a[l] > 0) ans += a[l] * t;
else ans -= -a[l] * s;
a[l] += x;
if(a[l] > 0) ans -= a[l] * t;
else ans += -a[l] * s;
if(r != n) {
if(a[r + 1] > 0) ans += a[r + 1] * t;
else ans -= -a[r + 1] * s;
a[r + 1] -= x;
if(a[r + 1] > 0) ans -= a[r + 1] * t;
else ans += -a[r + 1] * s;
}
cout << ans << '\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... |