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;
typedef long long ll;
typedef long double ld;
#define int long long
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, q, s, t;
cin >> n >> q >> s >> t;
vector <int> a(n + 1);
for (int i = 0; i < n + 1; ++i) {
cin >> a[i];
}
vector <int> diff(n + 1);
for (int i = 1; i <= n; ++i) diff[i] = a[i] - a[i - 1];
ll ans = 0;
for (int i = 1; i <= n; ++i) {
if (diff[i] > 0) ans -= (ll)(diff[i]) * s;
else ans += (ll)(-diff[i]) * t;
}
for (int i = 0; i < q; ++i) {
int l, r, x;
cin >> l >> r >> x;
if (diff[l] > 0) {
ans += (ll)diff[l] * s;
}
else {
ans -= (ll)-diff[l] * t;
}
diff[l] += x;
if (diff[l] > 0) {
ans -= (ll)diff[l] * s;
}
else {
ans += (ll)-diff[l] * t;
}
if (r + 1 <= n) {
if (diff[r + 1] > 0) {
ans += (ll)diff[r + 1] * s;
}
else {
ans -= (ll)-diff[r + 1] * t;
}
diff[r + 1] -= x;
if (diff[r + 1] > 0) {
ans -= (ll)diff[r + 1] * s;
}
else {
ans += (ll)-diff[r + 1] * t;
}
}
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... |