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>
#define ll long long
using namespace std;
ll koliko[200005],povecaj,res=0,T,S,N,Q,u1,u2,r1,r2,r3,r4;
int main(){
cin>>N>>Q>>S>>T;
N++;
for(int i=1;i<=N;i++)
cin>>koliko[i];
for(int i=1;i<N;i++)
if(koliko[i]<koliko[i+1])
res-=S*abs(koliko[i]-koliko[i+1]);
else res+=T*abs(koliko[i]-koliko[i+1]);
// cout<<res<<endl;
while(Q--){
cin>>u1>>u2>>povecaj;
u1++;
u2++;
r1=koliko[u1-1];
r2=koliko[u1];
r3=koliko[u2];
r4=koliko[u2+1];
if(u1!=1){
if(r1<r2)
res+=(r2-r1)*S;
else res-=(r1-r2)*T;
}
if(u2!=N){
if(r3<r4)
res+=(r4-r3)*S;
else res-=(r3-r4)*T;
}
// cout<<res<<endl;
for(int i=u1;i<=u2;i++)
koliko[i]+=povecaj;
r2+=povecaj;
r3+=povecaj;
if(u1!=1){
if(r1<r2)
res-=(r2-r1)*S;
else res+=(r1-r2)*T;
}
if(u2!=N){
if(r3<r4)
res-=(r4-r3)*S;
else res+=(r3-r4)*T;
}
/* for(int i=1;i<=N;i++)
cout<<koliko[i]<<" ";
cout<<endl;*/
cout<<res<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |