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;
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
long long N, Q, S, T, Su=0, L, R, K;
cin >> N >> Q >> S >> T;
long long A[N+1], Di[N+1];
cin >> A[0];
for (int i = 1; i <= N; i++)
{
cin >> A[i];
Di[i-1] = A[i] - A[i-1];
if (Di[i-1] >= 0)
{
Su -= S*Di[i-1];
}
else
{
Su -= T*Di[i-1];
}
}
Di[N] = 0;
for (int i = 0; i < Q; i++)
{
cin >> L >> R >> K;
if (Di[L-1] > 0)
{
Su += S*Di[L-1];
}
else
{
Su += T*Di[L-1];
}
Di[L-1] += K;
if (Di[L-1] > 0)
{
Su -= S*Di[L-1];
}
else
{
Su -= T*Di[L-1];
}
if (R != N)
{
if (Di[R] > 0)
{
Su += S*Di[R];
}
else
{
Su += T*Di[R];
}
Di[R] -= K;
if (Di[R] > 0)
{
Su -= S*Di[R];
}
else
{
Su -= T*Di[R];
}
}
cout << Su << endl;
}
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... |