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;
int N, Q;
ll S, T, A[300001], D[300000];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> Q >> S >> T;
cin >> A[0];
for (int i = 0; i < N; i++)
{
cin >> A[i + 1];
D[i] = A[i + 1] - A[i];
}
ll res = 0;
for (int i = 0; i < N; i++)
res += max(0LL, -D[i]) * T - max(0LL, D[i]) * S;
int L, R;
ll x;
while (Q--)
{
cin >> L >> R >> x;
res -= max(0LL, -D[L-1]) * T - max(0LL, D[L-1]) * S;
if (R != N)
res -= max(0LL, -D[R]) * T - max(0LL, D[R]) * S;
D[R] -= x;
D[L-1] += x;
res += max(0LL, -D[L-1]) * T - max(0LL, D[L-1]) * S;
if (R != N)
res += max(0LL, -D[R]) * T - max(0LL, D[R]) * S;
cout << res << '\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... |