This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
using ll = long long;
template<class T> using V = vector<T>;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, M; ll S, T; cin >> N >> M >> S >> T;
V<ll> A(N+1); for(auto& x : A) cin >> x;
ll ans = 0;
V<ll> D(N); for(int i = 0; i < N; i++) D[i] = A[i] - A[i + 1];
auto upd = [&](int x) {
if (D[x] < 0) return S * D[x];
else return T * D[x];
};
for(int i = 0; i < N; i++) ans += upd(i);
for(int q = 0; q < M; q++) {
int l, r; ll x; cin >> l >> r >> x;
{
ans -= upd(l - 1);
D[l - 1] -= x;
ans += upd(l - 1);
}
if (r < N) {
ans -= upd(r);
D[r] += x;
ans += upd(r);
}
cout << ans << nl;
}
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... |