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 calc(i) abs(dif[i])*(dif[i]<0?T:-S)
using namespace std;
typedef long long ll;
const int MN=1e6+2;
int N,Q;
ll S,T,a[MN],dif[MN],ans=0;
int main() {
ios::sync_with_stdio(0);cin.tie(0);
cin>>N>>Q>>S>>T;
for(int i=0;i<=N;++i) {
cin>>a[i];
if(i) {
dif[i]=a[i]-a[i-1];
ans+=calc(i);
}
}
while(Q--) {
int l,r,x;
cin>>l>>r>>x;
if(r<N) {
ans-=calc(r+1);
dif[r+1]-=x;
ans+=calc(r+1);
}
ans-=calc(l);
dif[l]+=x;
ans+=calc(l);
cout<<ans<<'\n';
}
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... |