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>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, q;
ll s, t;
cin >> n >> q >> s >> t;
vector<ll> a(n + 1), b(n);
for (int i = 0; i < n + 1; i++) {
cin >> a[i];
}
ll ans = 0;
for (int i = 0; i < n; i++) {
b[i] = a[i] - a[i + 1];
if (b[i] < 0) ans += b[i] * s;
else ans += b[i] * t;
}
while (q--) {
int l, r, x;
cin >> l >> r >> x;
if (b[l - 1] < 0) ans -= b[l - 1] * s;
else ans -= b[l - 1] * t;
b[l - 1] -= x;
if (b[l - 1] < 0) ans += b[l - 1] * s;
else ans += b[l - 1] * t;
if (r == n) {
cout << ans << en;
continue;
}
if (b[r] < 0) ans -= b[r] * s;
else ans -= b[r] * t;
b[r] += x;
if (b[r] < 0) ans += b[r] * s;
else ans += b[r] * t;
cout << ans << en;
}
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... |