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=200005;
long long tree[4*MAXN],lazy[4*MAXN];
int A[MAXN];
void updatenode(int now,int L,int R,int val){
tree[now]+=(1LL*(R-L+1)*val);
lazy[now]+=val;
}
void pushdown(int now,int L,int R){
int mid=(L+R)/2;
updatenode(2*now,L,mid,lazy[now]);
updatenode(2*now+1,mid+1,R,lazy[now]);
lazy[now]=0;
}
void build(int now,int L,int R){
if(L==R){
tree[now]=A[L];
return;
}
int mid=(L+R)/2;
build(2*now,L,mid);
build(2*now+1,mid+1,R);
tree[now]=tree[2*now]+tree[2*now+1];
}
int query(int now,int L,int R,int x,int y){
if(L>=x && R<=y)return tree[now];
if(L>y || R<x)return 0;
pushdown(now,L,R);
int mid=(L+R)/2;
return query(2*now,L,mid,x,y)+query(2*now+1,mid+1,R,x,y);
}
void update(int now,int L,int R,int x,int y,int val){
if(L>=x && R<=y){
updatenode(now,L,R,val);
return;
}
if(L>y || R<x)return;
int mid=(L+R)/2;
pushdown(now,L,R);
update(2*now,L,mid,x,y,val);
update(2*now+1,mid+1,R,x,y,val);
tree[now]=tree[2*now]+tree[2*now+1];
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int N,Q,S,T,L,R,P,U,V,W,X;
cin >> N >> Q >> S >> T;
for(int i=0;i<=N;i++)cin >> A[i];
build(1,1,N);
long long ans=0;
for(int i=1;i<=N;i++){
if(A[i-1]<=A[i])ans-=(1LL*S*(A[i]-A[i-1]));
else ans+=(1LL*T*(A[i-1]-A[i]));
}
while(Q--){
cin >> L >> R >> P;
long long U=0,V=query(1,1,N,L,L);
if(L>=2)U=query(1,1,N,L-1,L-1);
if(U<=V)ans+=(1LL*S*(V-U));
else ans-=(1LL*T*(U-V));
long long W=query(1,1,N,R,R),X;
if(R+1<=N){
X=query(1,1,N,R+1,R+1);
if(W<=X)ans+=(1LL*S*(X-W));
else ans-=(1LL*T*(W-X));
}
update(1,1,N,L,R,P);
V=query(1,1,N,L,L);
W=query(1,1,N,R,R);
if(U<=V)ans-=(1LL*S*(V-U));
else ans+=(1LL*T*(U-V));
if(R+1<=N){
if(W<=X)ans-=(1LL*S*(X-W));
else ans+=(1LL*T*(W-X));
}
cout << ans << '\n';
}
return 0;
}
Compilation message (stderr)
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:55:20: warning: unused variable 'U' [-Wunused-variable]
55 | int N,Q,S,T,L,R,P,U,V,W,X;
| ^
foehn_phenomena.cpp:55:22: warning: unused variable 'V' [-Wunused-variable]
55 | int N,Q,S,T,L,R,P,U,V,W,X;
| ^
foehn_phenomena.cpp:55:24: warning: unused variable 'W' [-Wunused-variable]
55 | int N,Q,S,T,L,R,P,U,V,W,X;
| ^
foehn_phenomena.cpp:55:26: warning: unused variable 'X' [-Wunused-variable]
55 | int N,Q,S,T,L,R,P,U,V,W,X;
| ^
foehn_phenomena.cpp:83:23: warning: 'X' may be used uninitialized in this function [-Wmaybe-uninitialized]
83 | else ans+=(1LL*T*(W-X));
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |