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;
long long D[1000001];
int main(){
ios_base::sync_with_stdio(0), cin.tie(0);
int N, Q, S, T; cin>>N>>Q>>S>>T;
long long ans = 0;
for(int i=0, pre=0; i<=N; ++i){
int x; cin>>x;
D[i] = x - pre;
if(D[i]>0) ans -= S*D[i];
else ans -= T*D[i];
pre = x;
}
while(Q--){
int s,e,v; cin>>s>>e>>v;
if(D[s]>0) ans += S*D[s];
else ans += T*D[s];
D[s] += v;
if(D[s]>0) ans -= S*D[s];
else ans -= T*D[s];
if(e<N){
if(D[e+1]>0) ans += S*D[e+1];
else ans += T*D[e+1];
D[e+1] -= v;
if(D[e+1]>0) ans -= S*D[e+1];
else ans -= T*D[e+1];
}
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... |