Submission #933009

# Submission time Handle Problem Language Result Execution time Memory
933009 2024-02-24T19:35:35 Z borisAngelov Sterilizing Spray (JOI15_sterilizing) C++17
0 / 100
231 ms 41888 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 100005;
const int maxStates = 30;

int n, q, k;

int a[maxn];

long long tree[4 * maxn][maxStates + 5];
int lazy[4 * maxn];

void build(int node, int l, int r)
{
    lazy[node] = 0;

    if (l == r)
    {
        tree[node][0] = a[l];

        for (int i = 1; i <= maxStates; ++i)
        {
            tree[node][i] = tree[node][i - 1] / k;
        }

        return;
    }

    int mid = (l + r) / 2;

    build(2 * node, l, mid);
    build(2 * node + 1, mid + 1, r);

    for (int i = 0; i <= maxStates; ++i)
    {
        tree[node][i] = tree[2 * node][i] + tree[2 * node + 1][i];
    }
}

void pushLazy(int node, int l, int r)
{
    if (lazy[node] == 0)
    {
        return;
    }

    for (int i = 0; i <= maxStates; ++i)
    {
        if (i + lazy[node] <= maxStates)
        {
            tree[node][i] = tree[node][i + lazy[node]];
        }
        else
        {
            tree[node][i] = 0;
        }
    }

    if (l != r)
    {
        lazy[2 * node] += lazy[node];
        lazy[2 * node + 1] += lazy[node];
    }

    lazy[node] = 0;
}

void updatePoint(int node, int l, int r, int pos, int val)
{
    pushLazy(node, l, r);

    if (l == r)
    {
        lazy[node] = 0;

        a[pos] = val;
        tree[node][0] = a[pos];

        for (int i = 1; i <= maxStates; ++i)
        {
            tree[node][i] = tree[node][i - 1] / k;
        }

        return;
    }

    int mid = (l + r) / 2;

    if (pos <= mid)
    {
        updatePoint(2 * node, l, mid, pos, val);
    }
    else
    {
        updatePoint(2 * node + 1, mid + 1, r, pos, val);
    }

    for (int i = 0; i <= maxStates; ++i)
    {
        tree[node][i] = tree[2 * node][i] + tree[2 * node + 1][i];
    }
}

void updateRange(int node, int l, int r, int ql, int qr)
{
    pushLazy(node, l, r);

    if (l > qr || r < ql)
    {
        return;
    }

    if (ql <= l && r <= qr)
    {
        ++lazy[node];
        pushLazy(node, l, r);
        return;
    }

    int mid = (l + r) / 2;

    updateRange(2 * node, l, mid, ql, qr);
    updateRange(2 * node + 1, mid + 1, r, ql, qr);

    for (int i = 0; i <= maxStates; ++i)
    {
        tree[node][i] = tree[2 * node][i] + tree[2 * node + 1][i];
    }
}

long long query(int node, int l, int r, int ql, int qr)
{
    pushLazy(node, l, r);

    if (l > qr || r < ql)
    {
        return 0;
    }

    if (ql <= l && r <= qr)
    {
        return tree[node][0];
    }

    int mid = (l + r) / 2;

    return query(2 * node, l, mid, ql, qr) + query(2 * node + 1, mid + 1, r, ql, qr);
}

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

int main()
{
    fastIO();

    cin >> n >> q >> k;

    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
    }

    build(1, 1, n);

    for (int i = 1; i <= q; ++i)
    {
        int type;
        cin >> type;

        if (type == 1)
        {
            int pos, val;
            cin >> pos >> val;
            updatePoint(1, 1, n, pos, val);
        }
        else if (type == 2)
        {
            int l, r;
            cin >> l >> r;
            updateRange(1, 1, n, l, r);
        }
        else if (type == 3)
        {
            int l, r;
            cin >> l >> r;
            cout << query(1, 1, n, l, r) << "\n";
        }
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 231 ms 41888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 57 ms 7132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 160 ms 41456 KB Output isn't correct
2 Halted 0 ms 0 KB -