Submission #374546

#TimeUsernameProblemLanguageResultExecution timeMemory
374546khkakjFoehn Phenomena (JOI17_foehn_phenomena)C++14
0 / 100
550 ms9452 KiB
#include <bits/stdc++.h>

using namespace std;

int a[200005],b[200005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,q,s,t;
    cin>>n>>q>>s>>t;
    for(int i=0;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++)
        b[i]=a[i]-a[i-1];
    int poz=0,neg=0;
    for(int i=1;i<=n;i++)
    {
        if(b[i]>=0)
            poz+=b[i];
        else
            neg-=b[i];
    }
    while(q--)
    {
        int l,r,x;
        cin>>l>>r>>x;
        //L
        if(x==0)
            continue;
        if(b[l]>=0)
        {
            if(x>=0)
            {
                poz+=x;
                b[l]+=x;
            }
            else
            {
                if(b[l]+x<0)
                {
                    poz-=b[l];
                    neg-=b[l]+x;
                    b[l]+=x;
                }
                if(b[l]+x>=0)
                {
                    b[l]+=x;
                    poz+=x;
                }
            }
        }
        else
        {
            if(x<=0)
            {
                b[l]+=x;
                neg-=x;
            }
            else
            {
                if(b[l]+x>0)
                {
                    neg+=b[l];
                    poz+=x+b[l];
                    b[l]+=x;
                }
                if(b[l]+x<=0)
                {
                    b[l]+=x;
                    neg-=x;
                }
            }
        }
        if(r==n)
            goto ispis;
        x=0-x;
        r++;
        if(b[r]>=0)
        {
            if(x>=0)
            {
                poz+=x;
                b[r]+=x;
            }
            else
            {
                if(b[r]+x<0)
                {
                    poz-=b[r];
                    neg-=b[r]+x;
                    b[r]+=x;
                }
                if(b[r]+x>=0)
                {
                    b[r]+=x;
                    poz+=x;
                }
            }
        }
        else
        {
            if(x<=0)
            {
                b[r]+=x;
                neg-=x;
            }
            else
            {
                if(b[r]+x>0)
                {
                    neg+=b[r];
                    poz+=x+b[r];
                    b[r]+=x;
                }
                if(b[r]+x<=0)
                {
                    b[r]+=x;
                    neg-=x;
                }
            }
        }
ispis:
        cout<<t*neg-s*poz<<endl;
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...