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 <iostream>
#define int long long
using namespace std;
int a[200005];
int raz[200005];
int32_t main()
{
int n, q, s, t;
cin >> n >> q >> s >> t;
for (int i = 0; i <= n; i++)
cin >> a[i];
int rez = 0;
for (int i = 0; i < n; i++)
{
raz[i] = a[i]-a[i+1];
rez += raz[i]*(raz[i] < 0 ? s : t);
}
while (q--)
{
int l, r, x;
cin >> l >> r >> x;
l--;
if (x < 0)
{
// cout << "tets\n";
x = abs(x);
if (raz[l] < 0)
rez -= raz[l]*s;
else
rez -= raz[l]*t;
raz[l] += x;
// cout << l << " " << raz[l] << " " << x << "\n";
if (raz[l] < 0)
rez += raz[l]*s;
else
rez += raz[l]*t;
if (r < n)
{
if (raz[r] < 0)
rez -= raz[r]*s;
else
rez -= raz[r]*t;
raz[r] -= x;
if (raz[r] < 0)
rez += raz[r]*s;
else
rez += raz[r]*t;
}
}
else if (x > 0)
{
x = abs(x);
if (raz[l] < 0)
rez -= raz[l]*s;
else
rez -= raz[l]*t;
raz[l] -= x;
if (raz[l] < 0)
rez += raz[l]*s;
else
rez += raz[l]*t;
if (r < n)
{
if (raz[r] < 0)
rez -= raz[r]*s;
else
rez -= raz[r]*t;
raz[r] += x;
if (raz[r] < 0)
rez += raz[r]*s;
else
rez += raz[r]*t;
}
}
// for (int i = 0; i < n; i++)
// cout << raz[i] << " ";
// cout << "\n";
cout << rez << "\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... |