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 ll long long
#define fi first
#define sec second
#define pb push_back
#define pqueue priority_queue
#define int long long
#define pii pair<int,int>
#define supercepat ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
using namespace std;
int tc,ans=0,n,q,s,t,l,r,x;
int a[200005];
int in1[200005];
int tree[400100];
void gas(int x){
if(x>n) return;
if(in1[x]>in1[x-1]) a[x]=(in1[x]-in1[x-1])*s*-1;
else a[x]=(in1[x-1]-in1[x])*t;
}
void build(int tidx,int tl,int tr){
if(tl==tr){
tree[tidx]=a[tl];
}
else{
int tmid=(tl+tr)/2;
build(2*tidx,tl,tmid);
build(2*tidx+1,tmid+1,tr);
tree[tidx]=tree[2*tidx]+tree[2*tidx+1];
}
}
void update(int tidx,int tl,int tr,int i,int x){
if(tl==tr){
tree[tidx]=x;
}
else{
int tmid=(tl+tr)/2;
if(i<=tmid){
update(2*tidx,tl,tmid,i,x);
}
else{
update(2*tidx+1,tmid+1,tr,i,x);
}
tree[tidx]=tree[2*tidx]+tree[2*tidx+1];
}
}
main(){
supercepat;
cin>>n>>q>>s>>t;
for(int i=0;i<=n;i++){
cin>>in1[i];
if(i>=1){
if(in1[i]>in1[i-1]) a[i]=(in1[i]-in1[i-1])*s*-1;
else a[i]=(in1[i-1]-in1[i])*t;
}
}
build(1,1,n);
while(q--){
cin>>l>>r>>x;
in1[l]+=x; if(l!=r) in1[r]+=x;
gas(l);
gas(r+1);
update(1,1,n,l,a[l]);
if(r+1<=n) update(1,1,n,r+1,a[r+1]);
cout<<tree[1]<<endl;
}
}
Compilation message (stderr)
foehn_phenomena.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
46 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |