#include <bits/stdc++.h>
#define int long long
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
using namespace std;
int n, q, s, t, a[maxn], st[4 * maxn], lazy[4 * maxn];
void build(int p, int l, int r){
if (l == r){
st[p] = a[l];
return;
}
int m = (l + r) >> 1;
build(2 * p, l, m);
build(2 * p + 1, m + 1, r);
st[p] = st[2 * p] + st[2 * p + 1];
}
void fix(int p, int l, int r){
if (!lazy[p]) return;
st[p] += (r - l + 1) * lazy[p];
if (l != r){
lazy[2 * p] += lazy[p];
lazy[2 * p + 1] += lazy[p];
}
lazy[p] = 0;
}
void update(int p, int l, int r, int u, int v, int val){
fix(p, l, r);
if (l > v || r < u) return;
if (l >= u && r <= v){
lazy[p] += val;
fix(p, l, r);
return;
}
int m = (l + r) >> 1;
update(2 * p, l, m, u, v, val);
update(2 * p + 1, m + 1, r, u, v, val);
st[p] = st[2 * p] + st[2 * p + 1];
}
int get(int p, int l, int r, int pos){
fix(p, l, r);
if (l > pos || r < pos) return 0;
if (l == r){
return st[p];
}
int m = (l + r) >> 1;
return get(2 * p, l, m, pos) + get(2 * p + 1, m + 1, r, pos);
// if (pos <= m) return get(2*p, l, m, pos);
// else return get(2*p+1, m+1, r, pos);
}
main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
if (fopen(".INP", "r"))
{
freopen(".INP", "r", stdin);
freopen(".OUT", "w", stdout);
}
cin >> n >> q >> s >> t;
int res = 0;
cin >> a[0];
for (int i = 1; i <= n; i++){
cin >> a[i];
if (a[i] > a[i - 1]) res -= (a[i] - a[i - 1]) * s;
else res += (a[i - 1] - a[i]) * t;
}
// cout << res;
// return 0;
build(1, 0, n);
while (q--){
int l, r, x; cin >> l >> r >> x;
int al1 = get(1, 0, n, l);
int al = get(1, 0, n, l - 1);
if (al1 > al) res += (al1 - al) * s;
else res -= (al - al1) * t;
if (r < n){
int ar = get(1, 0, n, r);
int ar1 = get(1, 0, n, r + 1);
if (ar1 > ar) res += (ar1 - ar) * s;
else res -= (ar - ar1) * t;
}
update(1, 0, n, l, r, x);
int al12 = get(1, 0, n, l);
int al2 = get(1, 0, n, l - 1);
if (al12 > al2) res -= (al12 - al2) * s;
else res += (al2 - al12) * t;
if (r < n){
int ar2 = get(1, 0, n, r);
int ar12 = get(1, 0, n, r + 1);
if (ar12 > ar2) res -= (ar12 - ar2) * s;
else res += (ar2 - ar12) * t;
}
cout << res << '\n';
}
return 0;
}
//TranTien
Compilation message (stderr)
foehn_phenomena.cpp:65:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
65 | main() {
| ^~~~
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | freopen(".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | freopen(".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |