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;
#define ll long long
#define pii pair<ll, int>
#define fi first
#define se second
const int N = 2e5 + 5;
ll n, q, s, t, ans = 0;
ll kc[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> q >> s >> t;
int pre_val;
for(int i = 0; i <= n; ++i) {
int x; cin >> x;
if(i) {
kc[i] = pre_val - x;
if(kc[i] >= 0) ans += t * kc[i];
else ans += s * kc[i];
}
pre_val = x;
}
while(q--) {
int l, r, x; cin >> l >> r >> x;
if(kc[l] >= 0) ans -= kc[l] * t;
else ans -= kc[l] * s;
kc[l] -= x;
if(kc[l] >= 0) ans += kc[l] * t;
else ans += kc[l] * s;
if(r < n) {
if(kc[r + 1] >= 0) ans -= kc[r + 1] * t;
else ans -= kc[r + 1] * s;
kc[r + 1] += x;
if(kc[r + 1] >= 0) ans += kc[r + 1] * t;
else ans += kc[r + 1] * s;
}
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... |