이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
const int maxn = 2e5 + 5;
int n, q, s, t, a[maxn];
struct node {
long long front, back;
long long s, g;
node() : front(0), back(0), s(0), g(0) {}
node(long long f, long long b, long long s, long long g) : front(f), back(b), s(s), g(g) {}
node operator+(const node &o) const {
node res = *this;
res.g += o.g;
res.s += o.s;
if(res.back < o.front) res.s += (o.front - res.back);
else res.g += (res.back - o.front);
res.back = o.back;
return res;
}
} tree[maxn * 4];
int lazy[maxn * 4];
struct segment_tree {
int n;
segment_tree() {}
segment_tree(int n) : n(n) {}
void build(int ind, int l, int r) {
if(l == r) {
tree[ind] = node(a[l], a[l], 0, 0);
return;
}
int mid = (l + r) / 2;
build(ind * 2, l, mid);
build(ind * 2 + 1, mid + 1, r);
tree[ind] = tree[ind * 2] + tree[ind * 2 + 1];
}
void down(int ind, int l, int r) {
tree[ind].front += lazy[ind];
tree[ind].back += lazy[ind];
if(l != r) {
lazy[ind * 2] += lazy[ind];
lazy[ind * 2 + 1] += lazy[ind];
}
lazy[ind] = 0;
}
void update(int ind, int l, int r, int x, int y, int val) {
if(lazy[ind]) down(ind, l, r);
if(l > y || r < x) return;
if(x <= l and r <= y) {
lazy[ind] += val;
down(ind, l, r);
return;
}
int mid = (l + r) / 2;
update(ind * 2, l, mid, x, y, val);
update(ind * 2 + 1, mid + 1, r, x, y, val);
tree[ind] = tree[ind * 2] + tree[ind * 2 + 1];
}
node get(int ind, int l, int r, int x, int y) {
if(lazy[ind]) down(ind, l, r);
if(l > y || r < x) return node();
if(x <= l and r <= y) return tree[ind];
int mid = (l + r) / 2;
return get(ind * 2, l, mid, x, y) + get(ind * 2 + 1, mid + 1, r, x, y);
}
void update(int x, int y, int val) {
update(1, 1, n, x, y, val);
}
pair<long long, long long> get(int x, int y) {
node res = get(1, 1, n, x, y);
return {res.s, res.g};
}
} st;
void solve() {
cin >> n >> q >> s >> t;
++n;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
}
st = segment_tree(n);
st.build(1, 1, n);
long long ans = 0;
while(q--) {
int l, r, x; cin >> l >> r >> x;
++l, ++r;
st.update(l, r, x);
pair<long long, long long> res = st.get(1, n);
ans = 1ll * res.first * (-s) + 1ll * res.second * t;
cout << ans << '\n';
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |