// source problem :
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define int long long
#define lb lower_bound
#define ub upper_bound
#define MASK(i) (1LL << (i))
const int inf = 1e18;
void ckmax(int& f, int s)
{
f = (f > s ? f : s);
}
void ckmin(int& f, int s)
{
f = (f < s ? f : s);
}
int32_t main()
{
ios_base::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 = 0; i <= n; i++) cin >> a[i];
int cur = 0;
for (int i = n; i > 0; i--)
{
a[i] -= a[i - 1];
if (a[i] > 0) cur -= s * a[i];
else cur -= t * a[i];
}
while (q--)
{
int l, r, x;
cin >> l >> r >> x;
if (a[l] > 0) cur += s * a[l];
else cur += t * a[l];
a[l] += x;
if (a[l] > 0) cur -= s * a[l];
else cur -= t * a[l];
if (r < n)
{
if (a[r + 1] > 0) cur += s * a[r + 1];
else cur += t * a[r + 1];
a[r + 1] -= x;
if (a[r + 1] > 0) cur -= s * a[r + 1];
else cur -= t * a[r + 1];
}
cout << cur << '\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... |