Submission #804338

# Submission time Handle Problem Language Result Execution time Memory
804338 2023-08-03T08:07:02 Z math_rabbit_1028 Distributing Candies (IOI21_candies) C++17
0 / 100
379 ms 15556 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;

int c;

struct node {
    int val;
    int add, upp, low;
} tree[808080];

node merger(node lt_val, node rt_val) {
    return {lt_val.val + rt_val.val, 0, c, 0};
}

void propagate(int v, int st, int ed) {
    tree[v].val = max(min(tree[v].val + tree[v].add, tree[v].upp), tree[v].low);
    if (st != ed) {
        //c1 = tree[u].upp, d1 = tree[u].add, e1 = tree[u].low
        //c2 = tree[v].upp, d2 = tree[v].add, e2 = tree[v].low
        for (auto u : {2 * v, 2 * v + 1}) {
            tree[u].upp = min(tree[u].upp + tree[v].add, tree[v].upp);
            tree[u].add = tree[u].add + tree[v].add;
            tree[u].low = max(min(tree[u].low + tree[v].add, tree[v].upp), tree[v].low);
        }
    }
    tree[v].add = 0;
    tree[v].upp = c;
    tree[v].low = 0;
}

void init(int v, int st, int ed) {
    if (st == ed) {
        tree[v].val = 0;
        tree[v].add = 0;
        tree[v].upp = c;
        tree[v].low = 0;
        return;
    }
    int mid = (st + ed) / 2;
    init(2 * v, st, mid);
    init(2 * v + 1, mid + 1, ed);
    tree[v] = merger(tree[2 * v], tree[2 * v + 1]);
}

void update(int v, int st, int ed, int lt, int rt, int val) {
    propagate(v, st, ed);
    if (lt > ed || st > rt) return;
    if (lt <= st && ed <= rt) {
        tree[v].add += val;
        propagate(v, st, ed);
        return;
    }
    int mid = (st + ed) / 2;
    update(2 * v, st, mid, lt, rt, val);
    update(2 * v + 1, mid + 1, ed, lt, rt, val);
    tree[v] = merger(tree[2 * v], tree[2 * v + 1]);
}

int get(int v, int st, int ed, int idx) {
    propagate(v, st, ed);
    if (st > idx || ed < idx) return 0;
    if (st == idx && ed == idx) return tree[v].val;
    int mid = (st + ed) / 2;
    return get(2 * v, st, mid, idx) + get(2 * v + 1, mid + 1, ed, idx);
}

std::vector<int> distribute_candies(std::vector<int> C, std::vector<int> l,
                                    std::vector<int> r, std::vector<int> v) {
    int n = C.size();
    int q = l.size();
    std::vector<int> s(n);

    c = C[0];
    init(1, 1, n);
    for (int i = 0; i < q; i++) {
        update(1, 0, n - 1, l[i], r[i], v[i]);
    }

    for (int i = 0; i < n; i++) {
        s[i] = get(1, 0, n - 1, i);
    }

    return s;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 379 ms 15556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 155 ms 5100 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -