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;
typedef long long ll;
ll N, Q, S, T, X, L, R, diff[200005], cont[200005], init = 0;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N >> Q >> S >> T;
S = -S;
T = -T;
for (int i = 0; i <= N; ++i){
cin >> diff[i];
}
for (int i = N; i >= 1; --i){
diff[i] -= diff[i-1];
}
for (int i = 1; i <= N; ++i){
if (diff[i] < 0) cont[i] = T*diff[i];
else cont[i] = S*diff[i];
init += cont[i];
}
for (int i = 1; i <= Q; ++i){
cin >> L >> R >> X;
init -= cont[L];
if (R < N) init -= cont[R+1];
diff[L] += X;
if (R < N) diff[R+1] -= X;
if (diff[L] < 0) cont[L] = T*diff[L];
else cont[L] = S*diff[L];
if (diff[R+1] < 0) cont[R+1] = T*diff[R+1];
else cont[R+1] = S*diff[R+1];
init += cont[L];
if (R < N) init += cont[R+1];
cout << init << '\n';
/*
for (int j = 1; j <= N; ++j){
cout << diff[j] << ' ';
}
cout << '\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... |