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;
using ll = long long;
const int MAXN = 200010;
int N, Q;
ll S, T;
ll A[MAXN];
ll diff[MAXN];
ll ans;
ll get_cost(int p) {
if (p > N || diff[p] == 0) {
return 0;
} else if (diff[p] > 0) {
return diff[p] * S;
} else {
return -diff[p] * T;
}
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> N >> Q >> S >> T;
S = -S;
for (int i = 0; i <= N; i++) cin >> A[i];
for (int i = 1; i <= N; i++) {
diff[i] = A[i] - A[i-1];
ans += get_cost(i);
}
for (int q = 0; q < Q; q++) {
int l, r; ll x; cin >> l >> r >> x;
ans -= get_cost(l) + get_cost(r+1);
diff[l] += x;
diff[r+1] -= x;
ans += get_cost(l) + get_cost(r+1);
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... |