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 fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 2e5 + 5;
int N, Q;
ll S, T, A[MAXN], B[MAXN], ans;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> N >> Q >> S >> T;
for(int i=0; i<=N; i++) cin >> A[i];
for(int i=1; i<=N; i++) {
B[i] = A[i] - A[i-1];
if(B[i] >= 0) ans -= B[i] * S;
else ans -= B[i] * T;
}
while(Q--) {
int l, r, x; cin >> l >> r >> x;
if(B[l] >= 0) ans += B[l] * S;
else ans += B[l] * T;
if(r < N) {
if(B[r+1] >= 0) ans += B[r+1] * S;
else ans += B[r+1] * T;
}
B[l] += x;
if(r < N) B[r+1] -= x;
if(B[l] >= 0) ans -= B[l] * S;
else ans -= B[l] * T;
if(r < N) {
if(B[r+1] >= 0) ans -= B[r+1] * S;
else ans -= B[r+1] * T;
}
cout << ans << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |