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 ll long long
#define endl "\n"
using namespace std;
ll n, q, s, t;
const ll N = 1e6;
//ll sh[N], st[N];
ll lh[N], lt[N];
ll a[N/2], tmp[N/2];
void updateh(ll ind, ll l, ll r, ll i , ll j, ll x)
{
if(i==j)
{
if(i<l||i>r)
return;
lh[ind]+=x;
return;
}
ll mid = i + (j-i)/2;
if(lh[ind])
{
//sh[ind]+=(j-i+1)*lh[ind];
if(i!=j)
{
lh[ind*2+1]+=lh[ind];
lh[ind*2+2]+=lh[ind];
}
lh[ind] = 0;
}
if(i>r||j<l)
return;
if(i>=l&&j<=r)
{
//sh[ind]+=(j-i+1)*x;
if(i!=j)
{
lh[ind*2+1]+=x;
lh[ind*2+2]+=x;
}
return;
}
updateh(ind*2+1, l, r, i, mid, x);
updateh(ind*2+2, l, r, mid+1, j, x);
//sh[ind] = sh[ind*2+1]+sh[ind*2+2];
}
void updatet(ll ind, ll l, ll r, ll i , ll j, ll x)
{
if(i==j)
{
if(i<l||i>r)
return;
lt[ind]+=x;
return;
}
ll mid = i + (j-i)/2;
if(lt[ind])
{
//st[ind]+=(j-i+1)*lt[ind];
if(i!=j)
{
lt[ind*2+1]+=lt[ind];
lt[ind*2+2]+=lt[ind];
}
lt[ind] = 0;
}
if(i>r||j<l)
return;
if(i>=l&&j<=r)
{
//st[ind]+=(j-i+1)*x;
if(i!=j)
{
lt[ind*2+1]+=x;
lt[ind*2+2]+=x;
}
return;
}
updatet(ind*2+1, l, r, i, mid, x);
updatet(ind*2+2, l, r, mid+1, j, x);
//st[ind] = st[ind*2+1]+st[ind*2+2];
}
/*ll buildh(ll ind, ll l, ll r)
{
if(l==r)
{
return sh[ind]=a[l];
}
ll mid = l + (r-l)/2;
return sh[ind] = buildh(ind*2+1, l, mid) + buildh(ind*2+2, mid+1, r);
}*/
/*ll buildt(ll ind, ll l, ll r)
{
if(l==r)
{
return st[ind]=tmp[l];
}
ll mid = l + (r-l)/2;
return st[ind] = buildt(ind*2+1, l, mid) + buildt(ind*2+2, mid+1, r);
}*/
ll geth(ll ind, ll l, ll r, ll poz)
{
if(l==r)
return a[l]+lh[ind];
if(lh[ind])
{
//sh[ind]+=(r-l+1)*lh[ind];
if(l!=r)
{
lh[ind*2+1]+=lh[ind];
lh[ind*2+2]+=lh[ind];
}
lh[ind] = 0;
}
ll mid = l + (r-l)/2;
if(poz>mid)
return geth(ind*2+2, mid+1, r, poz);
else
return geth(ind*2+1, l, mid, poz);
}
ll gett(ll ind, ll l, ll r, ll poz)
{
if(l==r)
return tmp[l]+lt[ind];
if(lt[ind])
{
//st[ind]+=(r-l+1)*lt[ind];
if(l!=r)
{
lt[ind*2+1]+=lt[ind];
lt[ind*2+2]+=lt[ind];
}
lt[ind] = 0;
}
ll mid = l + (r-l)/2;
if(poz>mid)
return gett(ind*2+2, mid+1, r, poz);
else
return gett(ind*2+1, l, mid, poz);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>q>>s>>t;
for(ll i = 0;i<=n;i++)
cin>>a[i];
for(ll i = 1;i<=n;i++)
{
if(a[i]<a[i-1])
{
tmp[i]=tmp[i-1]+(a[i-1]-a[i])*t;
}
else
{
tmp[i]=tmp[i-1]-(a[i]-a[i-1])*s;
}
}
//buildh(0, 0, n);
//buildt(0, 0, n);
for(ll i = 0;i<q;i++)
{
ll l, r, x;
cin>>l>>r>>x;
ll t1 = gett(0, 0, n, l-1);
ll t2 = gett(0, 0, n, l);
ll h1 = geth(0, 0, n, l-1);
ll h2 = geth(0, 0, n, l);
h2+=x;
ll t22;
if(h2<h1)
{
t22 = t1 + (h1-h2)*t;
}
else
{
t22 = t1 - (h2-h1)*s;
}
ll deltat = t22 - t2;
updatet(0, l, r, 0, n, deltat);
updateh(0, l, r, 0, n, x);
if(r!=n)
{
ll h1 = geth(0, 0, n, r);
ll h2 = geth(0, 0, n, r+1);
ll t1 = gett(0, 0, n, r);
ll t2 = gett(0, 0, n, r+1);
ll t22;
if(h2<h1)
{
t22 = t1 + (h1-h2)*t;
}
else
{
t22 = t1 - (h2-h1)*s;
}
deltat = t22 - t2;
updatet(0, r+1, n, 0, n, deltat);
}
cout<<gett(0, 0, n, n)<<endl;
}
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... |