#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define pa pair<ll, ll>
#define fi first
#define se second
#define bit(mask, j) ((mask >> j) & 1)
#define t_test int t;cin >> t;while(t--)
const ll mod = 1e9 + 7;
const ll INF = 1e18;
inline void adm(ll &x){if(x>=mod)x%=mod;else if(x<0)x+=mod;}
//--------------------------------------------------------------------
ll S, T, n, q;
ll calc(ll x, ll y) {
if(x < y) {
return (x - y) * S;
}
return (x - y) * T;
}
const ll N = 2e5 + 10;
ll a[N];
const int maxbit = 2e5 + 10;
ll BIT[maxbit];
void update(int x, ll val, int _n) {
while(x <= _n) {
BIT[x] += val;
x += x & -x;
}
}
ll get(int x) {
x++;
ll res = 0;
while(x > 0) {
res += BIT[x];
x -= x & -x;
}
return res;
}
void update_lr(int l, int r, ll val, int _n) {
l++,r++;
update(l, val, _n);
update(r + 1, -val, _n);
}
int walk(int x, int _n) {
int pos = 0;
int LG = __lg(_n);
FORD(j, LG, 0) {
if(pos + (1 << j) <= _n && BIT[pos + (1 << j)] < x) {
pos += (1 << j);
x -= BIT[pos];
}
}
return pos + 1;
}
void hbmt() {
cin >> n >> q >> S >> T;
FOR(i, 0, n) {
cin >> a[i];
update_lr(i, i, a[i], n + 1);
}
ll res = 0;
FOR(i, 1, n) {
res += calc(a[i - 1], a[i]);
}
FOR(i, 1, q) {
ll l, r, x;
cin >> l >> r >> x;
res -= calc(get(l - 1), get(l));
if(r + 1 <= n)
res -= calc(get(r), get(r + 1));
update_lr(l, r, x, n + 1);
res += calc(get(l - 1), get(l));
if(r + 1 <= n) {
res += calc(get(r), get(r + 1));
}
cout << res << '\n';
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
if(fopen("hbmt.inp", "r")) {
freopen("hbmt.inp", "r", stdin);
freopen("hbmt.out", "w", stdout);
}
// t_test
hbmt();
return 0;
}
Compilation message (stderr)
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
89 | freopen("hbmt.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
90 | freopen("hbmt.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... |