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;
const int MaxN = 200002;
long long a[MaxN], kc[MaxN];
long long type[MaxN];
long long n, q, s, t, l, r, x, i;
long long ans;
int main(){
cin >> n >> q >> s >> t;
for(i=0;i<=n;i++)
cin >> a[i];
for(i=0;i<=n-1;i++){
kc[i] = a[i]-a[i+1];
if(kc[i]>=0)
type[i] = 0;
else
type[i] = 1;
ans += ((!type[i]) ? t : s)*kc[i];
}
for(i=0;i<q;i++){
cin >> l >> r >> x;
kc[l-1] -= x;
if(kc[l-1]>=0&&type[l-1]){
type[l-1] = 0;
ans = ans + kc[l-1]*t - (kc[l-1]+x)*s;
}
else if(kc[l-1]<0&&!type[l-1]){
type[l-1] = 1;
ans = ans + kc[l-1]*s - (kc[l-1]+x)*t;
}
else if(kc[l-1]>=0&&!type[l-1])
ans -= x*t;
else
ans -= x*s;
if(r<n){
kc[r] += x;
if(kc[r]>=0&&type[r]){
type[r] = 0;
ans = ans + kc[r]*t - (kc[r]-x)*s;
}
else if(kc[r]<0&&!type[r]){
type[r] = 1;
ans = ans + kc[r]*s - (kc[r]-x)*t;
}
else if(kc[r]>=0&&!type[r])
ans += x*t;
else
ans += x*s;
}
cout << ans << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |