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 N=2e5+10;
const int M=2e5;
long long arr[N],fw[N];
void update(int idx,long long val){
while(idx<=M+5){
fw[idx]+=val;
idx+=idx & -idx;
}
}
long long read(int idx){
long long sum=0;
while(idx>0){
sum+=fw[idx];
idx-=idx & -idx;
}
return sum;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,q;
long long s,t,sum=0;
cin>>n >>q >>s >>t >>arr[0];
for(int i=1;i<=n;i++) cin>>arr[i],update(i,arr[i]),update(i+1,-1*arr[i]);
for(int i=1;i<=n;i++){
if(arr[i]>arr[i-1]) sum-=s*(arr[i]-arr[i-1]);
else sum+=t*abs(arr[i]-arr[i-1]);
//cout<<sum <<" ";
}
// cout<<sum <<"\n";
while(q--){
int a,b;
long long c;
cin>>a >>b >>c;
long long l=read(a),pl=0,r=read(b),ar;
if(a!=1) pl=read(a-1);
if(b!=n) ar=read(b+1);
if(l<=pl && l+c>pl) sum-=t*(pl-l)+s*(l+c-pl)/*,cout<<-1 <<" " <<t*(pl-l)+s*(l+c-pl) <<"|"*/;
if(l>pl && l+c<=pl) sum+=s*(l-pl)+t*(pl-(l+c))/*,cout<<-2 <<" " <<s*(l-pl)+t*(pl-(l+c)) <<"|"*/;
if(b!=n && ar<=r && r+c<ar) sum-=t*(r-ar)+s*(ar-(r+c))/*,cout<<-3 <<" " <<t*(r-ar)+s*(ar-(r+c)) <<"|"*/;
if(b!=n && ar>r && ar<=r+c) sum+=s*(ar-r)+t*(r+c-ar)/*,cout<<-4 <<" " <<s*(ar-r)+t*(r+c-ar) <<"|"*/;
if(l>pl && l+c>pl) sum-=s*c/*,cout<<1 <<" " <<s*c <<"|"*/;
if(l<=pl && l+c<=pl) sum-=t*c/*,cout<<2 <<" " <<t*c <<"|"*/;
if(b!=n && ar<=r && ar<=r+c) sum+=t*c/*,cout<<3 <<" " <<t*c <<"|"*/;
if(b!=n && ar>r && ar>r+c) sum+=s*c/*,cout<<4 <<" " <<s*c <<"|"*/;
update(a,c),update(b+1,-1*c);
/*for(int i=1;i<=n;i++) cout<<read(i) <<" ";
cout<<"|";*/
cout<<sum;
cout<<"\n";
}
}
Compilation message (stderr)
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:44:20: warning: 'ar' may be used uninitialized in this function [-Wmaybe-uninitialized]
44 | if(b!=n && ar<=r && r+c<ar) sum-=t*(r-ar)+s*(ar-(r+c))/*,cout<<-3 <<" " <<t*(r-ar)+s*(ar-(r+c)) <<"|"*/;
| ~~~~~~~~~~~~~~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |