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 vi vector<int>
#define vll vector<long long>
#define pb push_back
using ll= long long;
#define fast_io ios::sync_with_stdio(0); cin.tie(0)
#define inpint(x) int x; cin>>x
#define inpll(x) long long x; cin>>x
#define fl(i, n) for(int i=0; i<n; i++)
#define flo(i, n) for(int i=1; i<=n; i++)
#define int long long
#define pi pair<int, int>
#define mp make_pair
#define ld long double
const int MOD = 7 + (int)1e9;
const int INF = (int)1e18;
//
void solve()
{
int n, q, s, t;
cin>>n>>q>>s>>t;
vector<int> a(n+1, 0);
vector<int> d(n+1, 0); // a[i+1] - a[i]
int ans = 0;
for(int i = 0; i<=n; i++)
{
cin>>a[i];
}
for(int i=0; i<n; i++)
{
d[i] = a[i+1] - a[i];
if(d[i]>=0) ans -= d[i]*s;
else ans -= d[i]*t;
}
for(int i=1; i<=q; i++)
{
int l, r, x;
cin>>l>>r>>x;
if(l!=0)
{
if(d[l-1]<0) ans += d[l-1]*t;
else ans += s*d[l-1];
d[l-1] += x;
if(d[l-1]>=0) ans -= d[l-1]*s;
else ans -= d[l-1]*t;
}
if(r!=n)
{
if(d[r]<0) ans += d[r]*t;
else ans += d[r]*s;
d[r] -= x;
if(d[r]>=0) ans -= d[r]*s;
else ans -= d[r]*t;
}
cout<<ans<<"\n";
}
}
signed main()
{
fast_io;
int t=1;
//cin>>t;
while(t--)
{
solve();
}
cout<<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... |