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 task "Phenomena"
#define lb lower_bound
#define ub upper_bound
#define alll(v) (v).begin(),(v).end()
#define szz(v) (v).size()
#define fi first
#define se second
#define pb push_back
#define FOR(i,a,b) for (ll i = (a), _b = (b); i <= _b; ++i)
#define FORD(i,b,a) for (ll i = (b), _a = (a); i >= _a; --i)
typedef long double ld;
typedef long long ll;
typedef pair<ll,ll> pii;
const ll MOD=1000000007; /// 998244353
const ll base=311; /// for hash actually
const ll N=2e5+5;
ll st[4*N],lazy[4*N],n,q,s,t,a[N];
void down(ll i, ll l, ll r)
{
ll t=lazy[i];
st[i<<1]+=t;
st[i<<1|1]+=t;
lazy[i<<1]+=t;
lazy[i<<1|1]+=t;
lazy[i]=0;
}
void upd(ll i, ll l, ll r, ll u, ll v, ll val)
{
if(u>r||v<l) return;
if(u<=l&&r<=v)
{
lazy[i]+=val;
st[i]+=val;
return;
}
down(i,l,r);
ll mid=(l+r)>>1;
upd(i<<1,l,mid,u,v,val);
upd(i<<1|1,mid+1,r,u,v,val);
}
ll get(ll i, ll l, ll r, ll p)
{
if(l==r) return st[i];
down(i,l,r);
ll mid=(l+r)>>1;
if(p<=mid) return get(i<<1,l,mid,p);
else return get(i<<1|1,mid+1,r,p);
}
void solved()
{
cin>>n>>q>>s>>t;
s=-s;
ll ans=0;
++n;
FOR(i,1,n)
{
cin>>a[i];
upd(1,1,n,i,i,a[i]);
}
FOR(i,1,n-1)
{
if(a[i]<a[i+1]) ans+=s*(a[i+1]-a[i]);
else ans+=t*(a[i]-a[i+1]);
}
while(q--)
{
ll l,r,x;
cin>>l>>r>>x;
++l,++r;
ll p1=get(1,1,n,l-1), p2=get(1,1,n,l);
if(l>1&&p1<p2) ans-=s*(p2-p1);
else ans-=t*(p1-p2);
// cout<<s*(p2-p1)<<endl;s
p1=get(1,1,n,r), p2=get(1,1,n,r+1);
if(r<n&&p1<p2) ans-=s*(p2-p1);
else ans-=t*(p1-p2);
// cout<<ans<<endl;
upd(1,1,n,l,r,x);
p1=get(1,1,n,l-1), p2=get(1,1,n,l);
if(l>1&&p1<p2) ans+=s*(p2-p1);
else ans+=t*(p1-p2);
p1=get(1,1,n,r), p2=get(1,1,n,r+1);
if(r<n&&p1<p2) ans+=s*(p2-p1);
else ans+=t*(p1-p2);
cout<<ans<<'\n';
/*FOR(i,1,n) cout<<get(1,1,n,i)<<' ';
cout<<endl;*/
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
if(fopen(task".inp","r"))
{
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
solved();
}
Compilation message (stderr)
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
99 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:100:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
100 | freopen(task".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |