#include <bits/stdc++.h>
#define int long long
using namespace std;
const int NMAX=2e5;
int n, q, s, t;
int v[NMAX+1];
struct AIB
{
int aib[NMAX+5];
AIB()
{
for(auto &x:aib)x=0;
}
void update(int poz, int val)
{
for(;poz<=NMAX; poz+=poz&(-poz))
aib[poz]+=val;
}
int get(int poz)
{
int sum=0;
for(; poz>0; poz-=poz&(-poz))
sum+=aib[poz];
return sum;
}
}aib;
signed main()
{
cin>>n>>q>>s>>t;
for(int i=0; i<=n; i++)
cin>>v[i];
int ans=0;
for(int i=1; i<=n; i++)
{
if(v[i]<v[i-1])ans+=t*(v[i-1]-v[i]);
else ans+=s*(v[i-1]-v[i]);
}
while(q--)
{
int l, r, x;
cin>>l>>r>>x;
int before_l = v[l-1]+aib.get(l-1), now_l = v[l]+aib.get(l);
if(now_l < before_l)ans-=t*(before_l-now_l);
else ans-=s*(before_l-now_l);
now_l+=x;
if(now_l < before_l)ans+=t*(before_l-now_l);
else ans+=s*(before_l-now_l);
if(r!=n)
{
int after_r = v[r+1]+aib.get(r+1), now_r = v[r]+aib.get(r);
if(after_r < now_r)ans-=t*(now_r-after_r);
else ans-=s*(now_r-after_r);
now_r+=x;
if(after_r < now_r)ans+=t*(now_r-after_r);
else ans+=s*(now_r-after_r);
}
aib.update(l, x);
aib.update(r+1, -x);
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... |