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;
#define ll long long
const int N=200050;
int n,q;
ll s,t,a[N],st[N*20],lzy[N*20];
void Build(int c,int l,int r){
if(l>r)return;
if(l==r){st[c]=a[l];return;}
int mid=l+r>>1;
Build(c*2+1,l,mid);Build(c*2+2,mid+1,r);
st[c]=st[c*2+1]+st[c*2+2];
}
ll Get(int c,int l,int r,int ss,int se){
if(lzy[c]!=0){
st[c]+=lzy[c]*(r-l+1);
lzy[c*2+1]+=lzy[c],lzy[c*2+2]+=lzy[c],lzy[c]=0;
}
if(l>r||l>se||r<ss)return (ll)0;
if(l>=ss&&r<=se)return st[c];
int mid=l+r>>1;
return Get(c*2+1,l,mid,ss,se)+Get(c*2+2,mid+1,r,ss,se);
}
void Add(int c,int l,int r,int ss,int se,ll val){
if(l>r||r<ss||l>se)return;
if(l>=ss&&r<=se){lzy[c]+=val;return;}
int mid=l+r>>1;
Add(c*2+1,l,mid,ss,se,val);
Add(c*2+2,mid+1,r,ss,se,val);
}
ll B(int id){return Get(0,0,n,id,id);}
mt19937 rng(time(0));
int main(){
scanf("%i %i %lld %lld",&n,&q,&s,&t);
for(int i=0;i<=n;i++)scanf("%lld",&a[i]);
//n=rng()%10+1,q=rng()%10+1;
//s=rng()%10+1,t=rng()%10+1;
//for(int i=1;i<=n;i++)a[i]=rng()%100+1;
ll ans=0;
for(int i=0;i<n;i++){
if(a[i]<a[i+1])ans-=(a[i+1]-a[i])*s;
else ans+=(a[i]-a[i+1])*t;
}
Build(0,0,n);
//ll bans=ans;
while(q--){
int l,r;
//if(l>r)swap(l,r);
ll val;
scanf("%i %i %lld",&l,&r,&val);
if(l>0){
ll x=B(l-1),y=B(l);
if(x>y)ans-=(x-y)*t;
else ans+=(y-x)*s;
}
if(r<n){
ll x=B(r),y=B(r+1);
if(x>y)ans-=(x-y)*t;
else ans+=(y-x)*s;
}
Add(0,0,n,l,r,val);
if(l>0){
ll x=B(l-1),y=B(l);
if(x>y)ans+=(x-y)*t;
else ans-=(y-x)*s;
}
if(r<n){
ll x=B(r),y=B(r+1);
if(x>y)ans+=(x-y)*t;
else ans-=(y-x)*s;
}
printf("%lld\n",ans);
//printf("bans:%lld\n",bans);
/*if(ans!=bans){
printf("WA\n");
printf("%lld %lld\n",ans,bans);
}*/
}
return 0;
}
Compilation message (stderr)
foehn_phenomena.cpp: In function 'void Build(int, int, int)':
foehn_phenomena.cpp:10:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
10 | int mid=l+r>>1;
| ~^~
foehn_phenomena.cpp: In function 'long long int Get(int, int, int, int, int)':
foehn_phenomena.cpp:21:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
21 | int mid=l+r>>1;
| ~^~
foehn_phenomena.cpp: In function 'void Add(int, int, int, int, int, long long int)':
foehn_phenomena.cpp:27:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
27 | int mid=l+r>>1;
| ~^~
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
34 | scanf("%i %i %lld %lld",&n,&q,&s,&t);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:35:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
35 | for(int i=0;i<=n;i++)scanf("%lld",&a[i]);
| ~~~~~^~~~~~~~~~~~~~
foehn_phenomena.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
50 | scanf("%i %i %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... |