#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
int n, q, s, t;
cin >> n >> q >> s >> t;
vector<int> a(n+1);
for (int &i : a) cin >> i;
long long curtemp = 0;
vector<long long> diff(n+1);
for (int i = 0; i < n; ++i)
{
diff[i] = a[i] - a[i+1];
if (diff[i] < 0) curtemp += 1LL*s*diff[i];
else curtemp += 1LL*t*diff[i];
}
while (q--)
{
int l, r, x; cin >> l >> r >> x;
if (l != 0)
{
if (diff[l-1] >= 0 && diff[l-1] - x < 0)
{
curtemp -= 1LL*t*diff[l-1];
curtemp += 1LL*s*(diff[l-1]-x);
}
else if (diff[l-1] < 0 && diff[l-1] - x >= 0)
{
curtemp -= 1LL*s*diff[l-1];
curtemp += 1LL*t*(diff[l-1]-x);
}
else curtemp -= 1LL*((diff[l-1] < 0) ? s : t)*x;
diff[l-1] -= x;
}
if (r != n)
{
if (diff[r] < 0 && diff[r] + x >= 0)
{
curtemp -= 1LL*s*diff[r];
curtemp += 1LL*t*(diff[r]+x);
}
else if (diff[r] >= 0 && diff[r] + x < 0)
{
curtemp -= 1LL*t*diff[r];
curtemp += 1LL*s*(diff[r]+x);
}
else curtemp += 1LL*((diff[r] < 0) ? s : t)*x;
diff[r] += x;
}
//for (int i = 0; i < n; ++i) cout << diff[i] << ' ';
cout << curtemp << '\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... |