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
void Solve() {
int n, q, dec, inc;
cin >> n >> q >> dec >> inc;
int a[n + 1], diff[n + 1];
for(int i = 0; i <= n; i++) {
cin >> a[i];
diff[i] = 0;
}
int curAns = 0;
for(int i = 1; i <= n; i++) {
diff[i] = a[i] - a[i - 1];
if(a[i] <= a[i - 1]) {
curAns += inc * (a[i - 1] - a[i]);
}
else {
curAns -= dec * (a[i] - a[i - 1]);
}
}
for(int i = 1; i <= q; i++) {
int l, r, x;
cin >> l >> r >> x;
curAns -= (diff[l] <= 0) ? (inc * (-diff[l])) : -(dec * diff[l]);
diff[l] += x;
curAns += (diff[l] <= 0) ? (inc * (-diff[l])) : -(dec * diff[l]);
if(r != n) {
curAns -= (diff[r + 1] <= 0) ? (inc * (-diff[r + 1])) : -(dec * diff[r + 1]);
diff[r + 1] -= x;
curAns += (diff[r + 1] <= 0) ? (inc * (-diff[r + 1])) : -(dec * diff[r + 1]);
}
cout << curAns << "\n";
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
Solve();
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... |