Submission #1263240

#TimeUsernameProblemLanguageResultExecution timeMemory
1263240chikien2009Foehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
240 ms22784 KiB
#include <bits/stdc++.h>

using namespace std;

void setup()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int n, q, s, t, a, b, c;

struct NODE
{
    long long pre = 0, suf = 0, val = 0, rem = 0;
    inline NODE operator+(NODE inp)
    {
        NODE res;
        res.pre = this->pre;
        res.suf = inp.suf;
        res.val = this->val + inp.val;
        if (this->suf < inp.pre)
        {
            res.val -= (long long)(inp.pre - this->suf) * s;
        }
        else
        {
            res.val += (long long)(this->suf - inp.pre) * t;
        }
        return res;
    }
};

struct SEGMENT_TREE
{
    NODE tree[800000];
    inline void UpdateNode(int ind, int l, int r)
    {
        if (l < r)
        {
            tree[ind << 1].rem += tree[ind].rem;
            tree[ind << 1 | 1].rem += tree[ind].rem;
        }
        tree[ind].pre += tree[ind].rem;
        tree[ind].suf += tree[ind].rem;
        tree[ind].rem = 0;
    }
    inline void Update(int ind, int l, int r, int x, int y, int v)
    {
        UpdateNode(ind, l, r);
        if (r < x || y < l)
        {
            return;
        }
        if (x <= l && r <= y)
        {
            tree[ind].rem = v;
            UpdateNode(ind, l, r);
            return;
        }
        int m = (l + r) >> 1;
        Update(ind << 1, l, m, x, y, v);
        Update(ind << 1 | 1, m + 1, r, x, y, v);
        tree[ind] = tree[ind << 1] + tree[ind << 1 | 1];
    }
} st;

int main()
{
    setup();

    cin >> n >> q >> s >> t;
    for (int i = 0; i <= n; ++i)
    {
        cin >> a;
        st.Update(1, 0, n, i, i, a);
    }
    while (q--)
    {
        cin >> a >> b >> c;
        st.Update(1, 0, n, a, b, c);
        cout << st.tree[1].val << "\n";
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...