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 int long long
signed main()
{
int n, q, s, t; cin >> n >> q >> s >> t;
vector<int> a(n + 1), dif(n + 1);
for (int i = 0; i <= n; i++){
cin >> a[i];
}
int ans = 0;
for (int i = 1; i <= n; i++){
dif[i] = a[i] - a[i - 1];
if (dif[i] > 0) ans += -1 * s * dif[i];
else ans += t * abs(dif[i]);
}
while(q--){
int l, r, x; cin >> l >> r >> x;
if (dif[l] > 0) ans -= -1 * s * dif[l];
else ans -= t * abs(dif[l]);
dif[l] += x;
if (dif[l] > 0) ans += -1 * s * dif[l];
else ans += t * abs(dif[l]);
if (r < n){
r++;
if (dif[r] > 0) ans -= -1 * s * dif[r];
else ans -= t * abs(dif[r]);
dif[r] -= x;
if (dif[r] > 0) ans += -1 * s * dif[r];
else ans += t * abs(dif[r]);
}
cout << ans << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |