#include <bits/stdc++.h>
using namespace std;
#define int long long
#define nl '\n'
struct BIT {
int n; vector<int> bit;
BIT(int n): n(n), bit(n + 1) {}
void update(int i, int x) {
for(; i <= n; i += i & -i) bit[i] += x;
}
int get(int i) {
int res = 0;
for(; i >= 1; i -= i & -i) res += bit[i];
return res;
}
void set(int i, int x) {
update(i, x - (get(i) - get(i - 1)));
}
};
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q, s, t; cin >> n >> q >> s >> t;
vector<int> a(n + 1), b(n + 1);
for(auto &x : a) cin >> x;
BIT fn(n);
for(int i = 1; i <= n; i++) {
b[i] = a[i - 1] - a[i];
if(b[i] > 0) fn.set(i, b[i] * t);
if(b[i] < 0) fn.set(i, b[i] * s);
}
while(q--) {
int l, r, x; cin >> l >> r >> x;
b[l] += -x;
if(b[l] > 0) fn.set(l, b[l] * t);
if(b[l] < 0) fn.set(l, b[l] * s);
r++;
if(r <= n) {
b[r] += x;
if(b[r] > 0) fn.set(r, b[r] * t);
if(b[r] < 0) fn.set(r, b[r] * s);
}
cout << fn.get(n) << nl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |