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 ll long long int
int main(){
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll n,q,s,t; cin>>n>>q>>s>>t;
ll a[n+1],b[n];
ll wind=0;
for (ll i=0;i<=n;i++) {
cin>>a[i];
if (i>0) {
b[i-1]=a[i]-a[i-1];
if (b[i-1]>0) {
wind-=s*b[i-1];
} else {
wind+=t*abs(b[i-1]);
}
}
}
while(q--) {
ll l,r,x; cin>>l>>r>>x;
b[l-1]+=x;
ll i=b[l-1]-x, j=b[l-1];
if (i>0 && j>0) {
wind+=s*(i-j);
} else if (j<=0 && i<=0) {
wind+=t*(i-j);
} else if (i<=0 && j>0) {
wind-=t*abs(i);
wind-=s*abs(j);
} else {
wind+=s*abs(i);
wind+=t*abs(j);
}
if (r<n) {
b[r]-=x;
i=b[r]+x, j=b[r];
if (i>0 && j>0) {
wind+=s*(i-j);
} else if (j<=0 && i<=0) {
wind+=t*(i-j);
} else if (i<=0 && j>0) {
wind-=t*abs(i);
wind-=s*abs(j);
} else {
wind+=s*abs(i);
wind+=t*abs(j);
}
}
cout<<wind<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |