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;
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
long long n,q,s,t;
cin>>n>>q>>s>>t;
long long diff[n];
long long x;cin>>x;long long ans = 0;
for(int i = 0;i<n;i++){
long long y ;cin>>y;
diff[i] = y-x;
if(diff[i]>=0){
ans-=s*diff[i];
}else ans+=t*(abs(diff[i]));
x = y;
}
while(q--){
long long l, r , x;
cin>>l>>r>>x;
if(l-1>=0){
if(diff[l-1]>=0){
ans+=s*diff[l-1];
}else ans-=t*(abs(diff[l-1]));
diff[l-1]+=x;
if(diff[l-1]>=0){
ans-=s*diff[l-1];
}else ans+=t*(abs(diff[l-1]));
}if(r<n){
if(diff[r]>=0){
ans+=s*diff[r];
}else ans-=t*(abs(diff[r]));
diff[r]-=x;
if(diff[r]>=0){
ans-=s*diff[r];
}else ans+=t*(abs(diff[r]));
}
cout<<ans<<"\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... |