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 all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define pil pair<int,long long>
const int maxn=2e5+9;
long long a[maxn];
long long b[maxn];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("temp.INP","r",stdin);
//freopen("temp.OUT","w",stdout);
int n,q;
long long s,t;
cin>>n>>q>>s>>t;
long long pos=0,neg=0;
for1(i,0,n)cin>>a[i];
for1(i,1,n){
b[i]=a[i]-a[i-1];
if (b[i]>=0)pos+=b[i];
else neg+=abs(b[i]);
}
//cout<<pos<<" "<<neg<<'\n';
for1(i,1,q){
int l,r;
long long x;
cin>>l>>r>>x;
if (b[l]>=0)pos-=b[l];
else neg-=abs(b[l]);
b[l]+=x;
if (b[l]>=0)pos+=b[l];
else neg+=abs(b[l]);
if (r+1<=n){
if (b[r+1]>=0)pos-=b[r+1];
else neg-=abs(b[r+1]);
b[r+1]-=x;
if (b[r+1]>=0)pos+=b[r+1];
else neg+=abs(b[r+1]);
}
cout<<-pos*s+neg*t<<'\n';
//cout<<pos<<" "<<neg<<'\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... |