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;
const int N = 1e5 + 5;
int n, ans, s, t, q;
int a[N], node[4 * N], p[N];
bool f[N];
void build_tree(int i, int l, int r){
if(l > r) return;
if(l == r){
p[i] = node[i] = a[l - 1] - a[l];
if(node[i] < 0) node[i] *= t;
else node[i] *= s;
return;
}
int mid = (l + r) / 2;
build_tree(i * 2, l, mid);
build_tree(i * 2 + 1, mid + 1, r);
node[i] = node[i * 2] + node[i * 2 + 1];
//node[i].t = node[i * 2].t + node[i * 2 + 1].t;
//node[i].s = node[i * 2].s + node[i * 2 + 1].s;
}
void update_2(int i, int l, int r, int pos, int val){
if(l > r || l > pos || r < pos) return;
if(l == r){
if(l == pos) {
p[i] -= val;
if(p[i] < 0) node[i] = p[i] * t;
else node[i] = p[i] * s;
}
return;
}
int mid = (l + r) / 2;
update_2(i * 2, l, mid, pos, val);
update_2(i * 2 + 1, mid + 1, r, pos, val);
node[i] = node[i * 2] + node[i * 2 + 1];
}
void update(int i, int l, int r, int pos, int val){
if(l > r || l > pos || r < pos) return;
if(l == r){
if(l == pos) {
p[i] += val;
if(p[i] < 0) node[i] = p[i] * t;
else node[i] = p[i] * s;
}
return;
}
int mid = (l + r) / 2;
update(i * 2, l, mid, pos, val);
update(i * 2 + 1, mid + 1, r, pos, val);
node[i] = node[i * 2] + node[i * 2 + 1];
}
signed main(){
//ios_base::sync_with_stdio(false);
//cin.tie(nullptr);
//freopen("ANTS.INP", "r", stdin);
//freopen("ANTS.OUT", "w", stdout);
cin >> n >> q >> t >> s;
for(int i = 0; i <= n; ++ i) cin >> a[i];
build_tree(1, 1, n);
while(q --){
int l, r, x;
cin >> l >> r >> x;
update_2(1, 1, n, l, x);
if(r < n)
update(1, 1, n, r + 1, x);
cout << node[1] << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |