This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long int
struct node {
int s = 0, l = 0, r = 0;
};
int arr[200005], lazy[4*200005], s, t;
node seg[4*200005];
void lazypropagate(int n, int l, int r) {
if (lazy[n]) {
seg[n].l += lazy[n];
seg[n].r += lazy[n];
if (l != r) {
lazy[2*n] += lazy[n];
lazy[2*n+1] += lazy[n];
}
lazy[n] = 0;
}
}
void build(int n, int l, int r) {
if (l == r) {
seg[n].l = arr[l];
seg[n].r = arr[l];
} else {
int m = (l+r)/2;
build(2*n, l, m);
build(2*n+1, m+1, r);
seg[n].s = seg[2*n].s + seg[2*n+1].s;
seg[n].l = seg[2*n].l;
seg[n].r = seg[2*n+1].r;
if (seg[2*n].r < seg[2*n+1].l) {
seg[n].s += abs(seg[2*n].r-seg[2*n+1].l)*s;
} else {
seg[n].s += abs(seg[2*n].r-seg[2*n+1].l)*t;
}
}
}
void update(int n, int l, int r, int a, int b, int v) {
lazypropagate(n, l, r);
if (b < l || r < a) {
return;
} else if (a <= l && r <= b) {
lazy[n] += v;
lazypropagate(n, l, r);
} else {
int m = (l+r)/2;
update(2*n, l, m, a, b, v);
update(2*n+1, m+1, r, a, b, v);
seg[n].s = seg[2*n].s + seg[2*n+1].s;
seg[n].l = seg[2*n].l;
seg[n].r = seg[2*n+1].r;
if (seg[2*n].r < seg[2*n+1].l) {
seg[n].s -= abs(seg[2*n].r-seg[2*n+1].l)*s;
} else {
seg[n].s += abs(seg[2*n].r-seg[2*n+1].l)*t;
}
}
}
void solve() {
int n, q;
cin >> n >> q >> s >> t;
for (int i = 0; i <= n; i++) {
cin >> arr[i];
}
build(1, 0, n);
while(q--) {
int l, r, x;
cin >> l >> r >> x;
update(1, 0, n, l, r, x);
cout << seg[1].s << endl;
}
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
t = 1;
while(t--) {
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |