/*
* Author: Nonoze
* Created: Sunday 16/11/2025
*/
#include <bits/stdc++.h>
using namespace std;
#ifndef DEBUG
#define dbg(...)
#endif
// #define cout cerr << "OUT: "
#define endl '\n'
#define endlfl '\n' << flush
#define quit(x) return (void)(cout << x << endl)
template<typename T> void read(T& x) { cin >> x; }
template<typename T1, typename T2> void read(pair<T1, T2>& p) { read(p.first), read(p.second); }
template<typename T> void read(vector<T>& v) { for (auto& x : v) read(x); }
template<typename T1, typename T2> void read(T1& x, T2& y) { read(x), read(y); }
template<typename T1, typename T2, typename T3> void read(T1& x, T2& y, T3& z) { read(x), read(y), read(z); }
template<typename T1, typename T2, typename T3, typename T4> void read(T1& x, T2& y, T3& z, T4& zz) { read(x), read(y), read(z), read(zz); }
template<typename T> void print(vector<T>& v) { for (auto& x : v) cout << x << ' '; cout << endl; }
#define sz(x) (int)(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(v) sort(all(v)), v.erase(unique(all(v)), (v).end())
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define cmin(a, b) a = min(a, b)
#define cmax(a, b) a = max(a, b)
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define QYES quit("YES")
#define QNO quit("NO")
#define int long long
#define double long double
const int inf = numeric_limits<int>::max() / 4;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9+7, LOG=20;
void solve();
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int tt=1;
// cin >> tt;
while(tt--) solve();
return 0;
}
int s, t;
template<class T, class U>
struct segtree {
vector<T> st;
vector<U> lazy;
int n;
T idElement;
U idUpdate;
void create(int _n, T idEl, U idUp) {
n=_n;
idElement=idEl;
idUpdate=idUp;
st.resize(n*4, idElement);
lazy.resize(n*4, idUpdate);
}
segtree(int _n, T idEl, U idUp) {
create(_n, idEl, idUp);
}
segtree(int _n, T idEl, U idUp, vector<int> &creation) {
assert(sz(creation)==_n);
create(_n, idEl, idUp);
build(0, 0, n-1, creation);
}
void build(int v, int l, int r, vector<int> &creation) {
if (l==r) {
st[v]={0, {creation[l], creation[l]}};
return;
}
int mid=(l+r)/2;
build(v*2+1, l, mid, creation);
build(v*2+2, mid+1, r, creation);
st[v]=combine(st[2*v+1], st[2*v+2]);
}
void propagate(int v, int l, int r) {
if (lazy[v]==idUpdate) return;
st[v]=apply(st[v], lazy[v], l, r);
if (l!=r) {
int mid=(l+r)/2;
lazy[2*v+1]=combinelazy(lazy[2*v+1], lazy[v], l, mid);
lazy[2*v+2]=combinelazy(lazy[2*v+2], lazy[v], mid+1, r);
}
lazy[v]=idUpdate;
}
T query(int v, int l, int r, int ql, int qr) {
propagate(v, l, r);
if (l>qr || r<ql) return idElement;
if (l>=ql && r<=qr) return st[v];
int mid=(l+r)/2;
T s1=query(v*2+1, l, mid, ql, qr);
T s2=query(v*2+2, mid+1, r, ql, qr);
return combine(s1, s2);
}
void update(int v, int l, int r, int ql, int qr, U upd) {
propagate(v, l, r);
if (l>qr || r<ql) return;
if (l>=ql && r<=qr) {
lazy[v]=upd;
propagate(v, l, r);
return;
}
int mid=(l+r)/2;
update(v*2+1, l, mid, ql, qr, upd);
update(v*2+2, mid+1, r, ql, qr, upd);
st[v]=combine(st[v*2+1], st[v*2+2]);
}
void build(vector<int> &creation) {
build(0, 0, n-1, creation);
}
T query(int l, int r) {
return query(0, 0, n-1, l, r);
}
void update(int l, int r, U upd) {
update(0, 0, n-1, l, r, upd);
}
void update(int point, U upd) {
update(point, point, upd);
}
T combine(T l, T r) { // between two children / queries
T ans={l.fi+r.fi+(l.se.se>=r.se.fi?(l.se.se-r.se.fi)*t:(l.se.se-r.se.fi)*s), mp(l.se.fi, r.se.se)};
return ans;
}
T apply(T curr, U upd, int l, int r) { // apply update to a node (from lazy)
T ans=curr;
ans.se.fi+=upd, ans.se.se+=upd;
return ans;
}
U combinelazy(U old_upd, U new_upd, int l, int r) { // combine two lazy updates
U ans=old_upd+new_upd;
return ans;
}
};
int n, k, m, q;
vector<int> a;
void solve() {
read(n, q, s, t); n++;
a.clear(), a.resize(n); read(a);
segtree<pair<int, pair<int, int>>, int> st(n, {0, {0, 0}}, 0, a);
while (q--) {
int l, r, v; read(l, r, v);
st.update(l, r, v);
cout << st.query(0, n-1).fi << endl;
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |