Submission #856361

# Submission time Handle Problem Language Result Execution time Memory
856361 2023-10-03T09:00:27 Z Namviet2704 Foehn Phenomena (JOI17_foehn_phenomena) C++17
0 / 100
279 ms 25368 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int N = 2e5 + 5;

int n, q, s, t;
int a[N];
struct st
{
    ll left, right, val;
    ll lazy;
} nodes[N * 4];

void down(int id)
{
    int t = nodes[id].lazy;
    nodes[id * 2].lazy += t;
    nodes[id * 2].left += t;
    nodes[id * 2].right += t;

    nodes[id * 2 + 1].lazy += t;
    nodes[id * 2 + 1].left += t;
    nodes[id * 2 + 1].right += t;

    nodes[id].lazy = 0;
}

st merge(st A, st B)
{
    if (A.right < B.left)
        A.val += B.val - (B.left - A.right) * s;
    else
        A.val += B.val + (A.right - B.left) * t;
    A.right = B.right;
    return A;
}

void build(int id, int l, int r)
{
    if (l == r)
    {
        nodes[id].left = nodes[id].right = a[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(id * 2, l, mid);
    build(id * 2 + 1, mid + 1, r);
    nodes[id] = merge(nodes[id * 2], nodes[id * 2 + 1]);
}

void update(int id, int l, int r, int u, int v, int val)
{
    if (v < l || r < u)
        return;
    if (u <= l && r <= v)
    {
        nodes[id].left += val;
        nodes[id].right += val;
        nodes[id].lazy = val;
        return;
    }
    int mid = (l + r) / 2;

    down(id);

    update(id * 2, l, mid, u, v, val);
    update(id * 2 + 1, mid + 1, r, u, v, val);

    nodes[id] = merge(nodes[id * 2], nodes[id * 2 + 1]);
}

int main()
{
    // freopen(task".inp", "r", stdin);
    // freopen(task".out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    cin >> n >> q >> s >> t;
    for (int i = 0; i <= n; i++)
        cin >> a[i];
    build(1, 0, n);
    for (int i = 1; i <= q; i++)
    {
        int x, y;
        ll val;
        cin >> x >> y >> val;
        update(1, 0, n, x, y, val);
        cout << nodes[1].val << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 279 ms 25368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -