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 n,q,s,t;
int a[2000005];
int diff[2000005];
int tong;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n>>q>>s>>t;
for(int i=0;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
diff[i]=a[i-1]-a[i];
if(diff[i]<0){
tong+=diff[i]*s;
}
else {
tong+=diff[i]*t;
}
}
while(q--){
int l,r,x;
cin>>l>>r>>x;
if(diff[l]<0) tong-=diff[l]*s;
else tong-=diff[l]*t;
diff[l]-=x;
if(diff[l]<0) tong+=diff[l]*s;
else tong+=diff[l]*t;
if(r<n){
if(diff[r+1]<0) tong-=diff[r+1]*s;
else tong-=diff[r+1]*t;
diff[r+1]+=x;
if(diff[r+1]<0) tong+=diff[r+1]*s;
else tong+=diff[r+1]*t;
}
cout<<tong<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |