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>
#define int long long
#define INF 1000000000000000
#define lchild(i) (i*2 + 1)
#define rchild(i) (i*2 + 2)
#define mid(l, u) ((l+u)/2)
#define x(p) p.first
#define y(p) p.second
#define MOD 998244353
using namespace std;
const int N = 200005;
int n, q, s, t;
int a[N];
int seg[4*N];
int laz[4*N];
int build(int l, int u, int i){
laz[i] = 0;
if(l==u) return seg[i] = a[l];
return seg[i] = min(build(l, mid(l, u), lchild(i)),build(mid(l, u) + 1, u, rchild(i)));
}
int query(int l, int u, int i, int uu){
if(laz[i]!=0){
seg[i]+=laz[i];
if(l!=u){
laz[lchild(i)]+=laz[i];
laz[rchild(i)]+=laz[i];
}
laz[i] = 0;
}
if(l>=uu && u<=uu) return seg[i];
if(l>uu || u<uu) return INF;
return min(query(l, mid(l, u), lchild(i), uu), query(mid(l, u)+1, u, rchild(i), uu));
}
int update(int l, int u, int i, int ll, int uu, int x){
if(laz[i]!=0){
seg[i]+=laz[i];
if(l!=u){
laz[lchild(i)]+=laz[i];
laz[rchild(i)]+=laz[i];
}
laz[i] = 0;
}
if(l>=ll && u<=uu){
seg[i]+=x;
if(l!=u){
laz[lchild(i)]+=x;
laz[rchild(i)]+=x;
}
return seg[i];
}
if(l>uu || u<ll) return seg[i];
return seg[i] = min(update(l, mid(l, u), lchild(i), ll, uu, x), update(mid(l, u)+1, u, rchild(i), ll, uu, x));
}
int toadd(int a, int b){
int tr = 0;
if(b>=a){
tr = (b-a)*(-s);
}
else{
tr = (a-b)*t;
}
return tr;
}
int get(int i){
return query(0, n, 0, i);
}
signed main(){
cin>>n>>q>>s>>t;
for(int i = 0;i<=n;i++) cin>>a[i];
int curr = 0;
for(int i = 0;i<n;i++){
curr+=toadd(a[i], a[i+1]);
}
build(0, n, 0);
while(q--){
int l, r, x;
cin>>l>>r>>x;
if(l>0) curr-=(toadd(get(l-1), get(l)));
if(r<n) curr-=(toadd(get(r), get(r+1)));
update(0, n, 0, l, r, x);
if(l>0) curr+=(toadd(get(l-1), get(l)));
if(r<n) curr+=(toadd(get(r), get(r+1)));
cout<<curr<<"\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... |