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>
const int N = 2e5 + 5;
using namespace std;
struct node {
long long l, r, val, lazy;
} lv[4*N];
bool operator == (node a, node b){
return ((a.l == b.l) && (a.r == b.r) && (a.val == b.val));
}
int n, q;
long long S, T, a[N];
node Merge_Node(node a, node b){
node ans; ans.l = a.l, ans.r = b.r; ans.val = a.val + b.val; ans.lazy = 0;
if (a.r >= b.l) ans.val += T*abs(a.r - b.l);
else ans.val -= S*abs(b.l - a.r);
return ans;
}
void dolazy(int i, int l, int r){
if (lv[i].lazy == 0) return;
lv[i].l += lv[i].lazy; lv[i].r += lv[i].lazy;
if (l != r){
lv[i*2].lazy += lv[i].lazy; lv[i*2+1].lazy += lv[i].lazy;
}
lv[i].lazy = 0;
}
void init(int i, int l, int r){
if (l == r){
lv[i].l = lv[i].r = a[l]; lv[i].val = 0;
return;
}
int mid = (l + r) / 2;
init(i*2, l, mid); init(i*2+1, mid+1, r);
lv[i] = Merge_Node(lv[i*2], lv[i*2+1]);
}
void update(int i, int l, int r, int L, int R, long long val){
dolazy(i, l, r);
if (L > r || l > R) return;
if (L <= l && r <= R) {
lv[i].lazy += val; dolazy(i, l, r);
return ;
}
int mid = (l + r) / 2;
update(i*2, l, mid, L, R, val); update(i*2+1, mid+1, r, L, R, val);
lv[i] = Merge_Node(lv[i*2], lv[i*2+1]);
}
int main(){
scanf("%d %d %lld %lld", &n, &q, &S, &T);
for (int i = 0; i <= n; i++) scanf("%lld", &a[i]);
init(1, 0, n);
while (q--){
long long l, r, val;
scanf("%lld%lld%lld", &l, &r, &val);
update(1, 0, n, l, r, val);
printf("%lld\n", lv[1].val);
}
}
Compilation message (stderr)
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:55:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %lld %lld", &n, &q, &S, &T);
^
foehn_phenomena.cpp:56:54: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (int i = 0; i <= n; i++) scanf("%lld", &a[i]);
^
foehn_phenomena.cpp:60:44: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld%lld", &l, &r, &val);
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |