Submission #290464

#TimeUsernameProblemLanguageResultExecution timeMemory
290464iliccmarkoFoehn Phenomena (JOI17_foehn_phenomena)C++14
0 / 100
35 ms13048 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"

using namespace std;
int n, q, s, t;
const int N = 4e5 + 5;
ll sh[N], st[N];
ll lh[N], lt[N];
ll a[N/2], tmp[N/2];

void updateh(int ind, int l, int r, int i , int j, int x)
{
    int 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(int ind, int l, int r, int i , int j, int x)
{
    int 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(int ind, int l, int r)
{
    if(l==r)
    {
        return sh[ind]=a[l];
    }
    int mid = l + (r-l)/2;
    return sh[ind] = buildh(ind*2+1, l, mid) + buildh(ind*2+2, mid+1, r);
}

ll buildt(int ind, int l, int r)
{
    if(l==r)
    {
        return st[ind]=tmp[l];
    }
    int mid = l + (r-l)/2;
    return st[ind] = buildt(ind*2+1, l, mid) + buildt(ind*2+2, mid+1, r);
}

ll geth(int ind, int l, int r, int poz)
{
    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;
    }
    if(l==r)
        return sh[ind];
    int 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(int ind, int l, int r, int poz)
{
    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;
    }
    if(l==r)
        return st[ind];
    int 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(int i = 0;i<=n;i++)
        cin>>a[i];
    for(int 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(int i = 0;i<q;i++)
    {
        int l, r, x;
        cin>>l>>r>>x;
            int t1 = gett(0, 0, n, l-1);
            int t2 = gett(0, 0, n, l);
            int h1 = geth(0, 0, n, l-1);
            int h2 = geth(0, 0, n, l);
            h2+=x;
            int t22;
            if(h2<h1)
            {
                t22 = t1 + (h1-h2)*t;
            }
            else
            {
                t22 = t1 - (h2-h1)*s;
            }
            int deltat = t22 - t2;
            updatet(0, l, r, 0, n, deltat);
        updateh(0, l, r, 0, n, x);
        if(r!=n)
        {
            int h1 = geth(0, 0, n, r);
            int h2 = geth(0, 0, n, r+1);
            int t1 = gett(0, 0, n, r);
            int t2 = gett(0, 0, n, r+1);
            int 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...