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 maxn = 1e5 + 5;
#define ll long long
ll v[maxn], vans[maxn];
ll bit[maxn];
void upd(int id, int val){
for(; id < maxn; id+=id&-id) bit[id] += val;
}
ll sum(int id){
ll rt = 0;
for(; id>0; id-=id&-id) rt += bit[id];
return rt;
}
int main(){
int n, q, s, t; cin >> n >> q >> s >> t;
for(int i = 0; i <= n; i++) cin >> v[i];
ll ans = 0;
for(int i = 0; i < n; i++){
if(v[i+1]>v[i]) vans[i] = -(v[i+1]-v[i])*s;
else vans[i] = (v[i]-v[i+1])*t;
ans += vans[i];
}
while(q--){
int l, r, x; cin >> l >> r >> x;
upd(l, x), upd(r+1, -x);
ll a=0, b=0;
a = v[l]+sum(l) - (v[l-1]+sum(l-1));
if(r<n) b = v[r+1]+sum(r+1) - (v[r]+sum(r));
if(a>0) a*=-s;
else a*=-t;
if(b>0) b*=-s;
else b*=-t;
ans -= vans[l-1] + vans[r];
ans += a+b;
vans[l-1] = a, vans[r] = b;
cout << ans << "\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... |