#include <bits/stdc++.h>
#define int long long
#define debug cout << "ok\n";
#define SQR(x) (1LL * ((x) * (x)))
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pli pair<ll,int>
#define vi vector<int>
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int ui;
using namespace std;
const int M = 1e9 + 7;
const int INF = 1e9 + 7;
const ll INFLL = (ll)2e18 + 7LL;
const ld PI = acos(-1);
const int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};
template<class _, class __>
bool minimize(_ &x, const __ y){
if(x > y){
x = y;
return true;
} else return false;
}
template<class _, class __>
bool maximize(_ &x, const __ y){
if(x < y){
x = y;
return true;
} else return false;
}
template<class _,class __>
void Add(_ &x, const __ y) {
x += y;
if (x >= M) {
x -= M;
}
return;
}
template<class _,class __>
void Diff(_ &x, const __ y) {
x -= y;
if (x < 0) {
x += M;
}
return;
}
//--------------------------------------------------------------
const int MaxN = 5e5+7;
int n,q,S,T,a[MaxN];
struct Nodes {
int aL;
int aR;
int Sum;
Nodes() {
aL = aR = Sum = -INFLL;
}
void Set(int v) {
aL = aR = v;
Sum = 0;
return;
}
void operator += (int v) {
aL += v;
aR += v;
}
} ;
Nodes operator + (Nodes a, Nodes b) {
if (a.Sum <= -INFLL) return b;
if (b.Sum <= -INFLL) return a;
Nodes res;
res.aL = a.aL;
res.aR = b.aR;
res.Sum = a.Sum + b.Sum;
if (a.aR < b.aL) res.Sum += S * (b.aL - a.aR);
else res.Sum += T * (b.aL - a.aR);
return res;
}
struct SegmentTree {
Nodes Tr[MaxN*4];
int lazy[MaxN*4];
void BT(int id,int l,int r) {
lazy[id] = 0;
if (l == r) {
Tr[id].Set(a[l]);
return;
}
int m = (l+r) >> 1;
BT(id<<1,l,m);
BT(id<<1|1,m+1,r);
Tr[id] = Tr[id<<1] + Tr[id<<1|1];
return;
}
void down(int id) {
if (lazy[id] == 0) return;
Tr[id<<1] += lazy[id];
lazy[id<<1] += lazy[id];
Tr[id<<1|1] += lazy[id];
lazy[id<<1|1] += lazy[id];
lazy[id] = 0;
return;
}
void UT(int id,int l,int r,int ls,int rs,int v) {
if (l > rs || r < ls) return;
if (ls <= l && r <= rs) {
Tr[id] += v;
lazy[id] += v;
return;
}
int m = (l+r) >> 1;
down(id);
UT(id<<1,l,m,ls,rs,v);
UT(id<<1|1,m+1,r,ls,rs,v);
Tr[id] = Tr[id<<1] + Tr[id<<1|1];
return;
}
} Seg;
void sol() {
cin >> n >> q >> S >> T;
for (int i=0;i<=n;i++) cin >> a[i];
Seg.BT(1,0,n);
for (int i=1;i<=q;i++) {
int l,r,v;
cin >> l >> r >> v;
Seg.UT(1,0,n,l,r,v);
cout << -Seg.Tr[1].Sum << '\n';
}
}
signed main() {
// freopen("test.inp","r",stdin);
// freopen("test.out","w",stdout);
FAST
int t=1;
// cin >> t;
while (t--) sol();
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |