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 ll long long
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, q, s, t;
cin >> n >> q >> s >> t;
vector<ll> diff(n); // diff i sama i+1;
ll prev, now;
ll diffAll = 0;
cin >> prev;
for (int i = 0; i < n; i++)
{
cin >> now;
diff[i] = prev - now;
if (diff[i] <= 0)
{
diffAll += (diff[i] * s);
}
else
{
diffAll += (diff[i] * t);
}
prev = now;
}
// for (auto x : diff)
// {
// cout << x;
// }
for (int i = 0; i < q; i++)
{
ll l, r, x;
cin >> l >> r >> x;
if (l > 0)
{
if (diff[l - 1] <= 0)
{
diffAll -= diff[l - 1] * s;
}
else
{
diffAll -= diff[l - 1] * t;
}
diff[l - 1] -= x;
if (diff[l - 1] <= 0)
{
diffAll += diff[l - 1] * s;
}
else
{
diffAll += diff[l - 1] * t;
}
}
if (r < n)
{
if (diff[r] <= 0)
{
diffAll -= diff[r] * s;
}
else
{
diffAll -= diff[r] * t;
}
diff[r] += x;
if (diff[r] <= 0)
{
diffAll += diff[r] * s;
}
else
{
diffAll += diff[r] * t;
}
}
cout << diffAll << "\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... |