답안 #804340

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
804340 2023-08-03T08:07:34 Z math_rabbit_1028 사탕 분배 (IOI21_candies) C++17
0 / 100
362 ms 15580 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, 0, n - 1);
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 362 ms 15580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 158 ms 5096 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -