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 a[200001],dp[200001];
int main(){
ll n,q,s,t,ih=0,baga=0;
cin >> n >> q >> s >> t;
cin >> a[0];
for(int i=1;i<=n;i++){
cin >> a[i];
if(a[i]>a[i-1]){
ih+=(a[i]-a[i-1]);
}
else baga+=(a[i-1]-a[i]);
dp[i]=a[i]-a[i-1];
}
for(int i=1;i<=q;i++){
//cout << ih << ' ' << baga << endl;
ll l,r,x;
cin >> l >> r >> x;
ll p=dp[l];
ll q=dp[l]+x;
if(p>0 && q>0){
ih+=x;
}
if(p>0 && q<=0){
ih-=p;
baga+=(abs(q));
}
if(p<=0 && q>0){
ih+=q;
baga-=(abs(p));
}
if(p<=0 && q<=0){
baga-=x;
}
dp[l]=q;
if(r!=n){
ll p=dp[r+1];
ll q=dp[r+1]-x;
if(p>0 && q>0){
ih-=x;
}
if(p>0 && q<=0){
ih-=p;
baga+=(abs(q));
}
if(p<=0 && q>0){
ih+=q;
baga-=(abs(p));
}
if(p<=0 && q<=0){
baga+=x;
}
dp[r+1]=q;
}
cout << -ih*s+baga*t << 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... |