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 int long long
int N,Q,S,T,L,R,X;
int A[200005];
int temp;
int B[200005];
signed main()
{
cin>>N>>Q>>S>>T;//S lebih tinggi, T lebih rendah
for(int i = 0;i<=N;i++)cin>>A[i];
T=-T;
S=-S;
// int ans=0;
// cout<<"temp"<<temp<<endl;
while(Q--){
cin>>L>>R>>X;
for(int i = L;i<=R;i++)A[i]+=X;
temp=0;
for(int i = 0;i<N;i++){
if(A[i+1]-A[i]>=0){
temp+=(A[i+1]-A[i])*S;
B[i]=(A[i+1]-A[i])*S;
}else{
temp+=(A[i+1]-A[i])*T;
B[i]=(A[i+1]-A[i])*T;
}
}
cout<<temp<<endl;
}
// for(int i = 0;i<N;i++)cout<<i<<";"<<B[i]<<endl;
return 0;
}
// if(L>0){
// if(A[L]+X-A[L-1]>0)ans+=(A[L]+X-A[L-1])*T;
// else ans+=(A[L]+X-A[L-1])*S;
// ans-=B[L-1];
// }
// if(R<N){
// if(A[R+1]-(A[R]+X)>0)ans+=(A[R+1]-(A[R]+X))*T;
// else ans+=(A[R+1]-(A[R]+X))*S;
// ans-=B[R];
// }
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |