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()
{
long long N, Q, U, D;
cin >> N >> Q >> U >> D;
vector<long long> alt(N + 1);
vector<long long> diff(N + 1);
long long sum = 0;
for (long long i = 0; i <= N; i++)
{
cin >> alt[i];
if (i == 0)
continue;
diff[i] = alt[i] - alt[i - 1];
if (diff[i] > 0)
sum -= diff[i] * U;
else
sum -= diff[i] * D;
}
for (long long i = 0; i < Q; i++)
{
long long l, r, x;
cin >> l >> r >> x;
if (x > 0)
{
if (diff[l] < 0)
{
sum -= min(abs(diff[l]), x) * D;
if (abs(diff[l]) < x)
sum -= (x + diff[l]) * U;
}
else
sum -= x * U;
diff[l] += x;
if (r != N)
{
if (diff[r + 1] > 0)
{
sum += min(diff[r + 1], x) * U;
if (diff[r + 1] < x)
sum += (x - diff[r + 1]) * D;
}
else
sum += x * D;
diff[r + 1] -= x;
}
}
else
{
if (diff[l] > 0)
{
sum += min(diff[l], abs(x)) * U;
if (diff[l] < abs(x))
sum += (abs(x) - diff[l]) * D;
}
else
sum += abs(x) * D;
diff[l] += x;
if (r != N)
{
if (diff[r + 1] < 0)
{
sum -= min(abs(diff[r + 1]), abs(x)) * D;
if (abs(diff[r + 1]) < abs(x))
sum -= (abs(x) + diff[r + 1]) * U;
}
else
sum -= abs(x) * U;
diff[r + 1] -= x;
}
}
cout << sum << '\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... |