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 int long long
using namespace std;
const int N = 2e5 + 5;
int n, q, s, t;
int l, r, x, res = 0;
int a[N];
void solve(int l, int r, int x)
{
int val = 0;
if (l > 0) {
val -= a[l-1] * (a[l-1] < 0 ? s : t);
a[l-1] -= x;
val += a[l-1] * (a[l-1] < 0 ? s : t);
}
if (r < n){
val -= a[r] * (a[r] < 0 ? s : t);
a[r] += x;
val += a[r] * (a[r] < 0 ? s : t);
}
res += val;
cout << res << "\n";
return;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> q >> s >> t;
int prev, nex; cin >> prev;
for (int i = 0;i < n;++i) {
cin >> nex;
a[i] = prev - nex;
res += (a[i] * (a[i] < 0 ? s : t));
prev = nex;
}
for (int i = 0;i < q;++i) {
cin >> l >> r >> x;
solve(l, r, x);
}
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... |