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
#define ull unsigned long long
#define inf 1e15
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define pii pair<int,int>
#define all(a) a.begin(),a.end()
#define rall(a) a.begin(),a.end(),greater<int>()
using namespace std;
#define maxn 200005
ll a[maxn];
int main(){
ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);
ll n,q,s,t;
cin >> n >>q>>s>>t;
for(int i = 0;i<=n;i++) cin >> a[i];
ll ans = 0;
for(int i = 0;i<n;i++){
if(a[i]<a[i+1]){
ans-=s*(a[i+1]-a[i]);
}else ans+=t*(a[i]-a[i+1]);
}
int l,r,x;
while(q--){
cin >> l >> r >> x;
//cout<<a[l-1]<< " "<<a[l]<< " "<<a[r]<<" "<<a[r+1]<<"\n";
if(r!=n){
if(a[r]<a[r+1]){
ans+=s*(a[r+1]-a[r]);
}else ans-=t*(a[r]-a[r+1]);
a[r]+=x;
if(a[r]<a[r+1]){
ans-=s*(a[r+1]-a[r]);
}else ans+=t*(a[r]-a[r+1]);
}
if(l==r&&r!=n) a[l]-=x;
if(a[l]>a[l-1]){
ans+=s*(a[l]-a[l-1]);
}else ans-=t*(a[l-1]-a[l]);
a[l]+=x;
if(a[l-1]<a[l]){
ans-=s*(a[l]-a[l-1]);
}else ans+=t*(a[l-1]-a[l]);
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... |