#include<bits/stdc++.h>
using namespace std;
void local() {
#define taskname ""
if(fopen(taskname".inp", "r")) {
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
}
#define ll long long
#define int long long
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
template <class X, class Y> bool mini(X& x, Y y) {return x > y ? x = y, true : false;}
template <class X, class Y> bool maxi(X& x, Y y) {return x < y ? x = y, true : false;}
const int N = 1e6 + 5;
struct FenwickTree {
using T = ll;
vector<T>bit; int n;
void init(int n_) {
bit.assign((n = n_) + 5, 0);
}
void update(int id, int x) {
for(; id <= n; id += id & -id) bit[id] += x;
}
T get(int id) {
if(id <= 0) return 0;
T sum = 0;
for(; id; id -= id & -id) sum += bit[id];
return sum;
}
T getRan(int l, int r) {
return get(r) - get(l - 1);
}
} fen;
ll res = 0;
int n, q, a[N], s, t;
ll pls_cal(int x, int y) {
if(x < y) return -1ll * s * (y - x);
return 1ll * t * (x - y);
}
signed main() {
fastio; local();
cin >> n >> q >> s >> t;
for(int i = 1; i <= n + 1; i++) cin >> a[i];
for(int i = 1; i <= n; i++) {
res += pls_cal(a[i], a[i + 1]);
}
fen.init(n + 1);
for(int i = 1; i <= q; i++) {
int l, r, x; cin >> l >> r >> x; l++; r++;
res -= pls_cal(a[l - 1] + fen.get(l - 1), a[l] + fen.get(l));
if(r < n + 1) res -= pls_cal(a[r] + fen.get(r), a[r + 1] + fen.get(r + 1));
fen.update(l, x); fen.update(r + 1, -x);
res += pls_cal(a[l - 1] + fen.get(l - 1), a[l] + fen.get(l));
if(r < n + 1) res += pls_cal(a[r] + fen.get(r), a[r + 1] + fen.get(r + 1));
cout << res << '\n';
}
}
Compilation message (stderr)
foehn_phenomena.cpp: In function 'void local()':
foehn_phenomena.cpp:7:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
7 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:8:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
8 | freopen(taskname".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... |