답안 #1020926

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1020926 2024-07-12T11:34:53 Z mdn2002 사탕 분배 (IOI21_candies) C++17
29 / 100
830 ms 1303972 KB
/*
Mayoeba Yabureru
*/
#include<bits/stdc++.h>
using namespace std;

struct Node {
    int valuel = 0, valuer = 0, lazyadd = 0, lazyset = -1;
    int left = -1, right = -1;
    Node() {}
};
Node st[55000006];
int cnt;
void push(int node, int l, int r) {
    int left = st[node].left, right = st[node].right;
    if (st[node].lazyset != -1) {
        //cout << '*' << l << ' ' << r << ' ' << st[node].lazyset << ' ' << st[node].lazyadd << endl;
        if (st[node].lazyset == 0) {
            st[node].valuel = 0;
            st[node].valuer = 0;
        }
        else {
            st[node].valuel = l;
            st[node].valuer = r;
        }
        st[node].valuel += st[node].lazyadd;
        st[node].valuer += st[node].lazyadd;
        if (l != r) {
            st[left].lazyset = st[right].lazyset = st[node].lazyset;
            st[left].lazyadd = st[right].lazyadd = 0;
            st[left].lazyadd += st[node].lazyadd;
            st[right].lazyadd += st[node].lazyadd;
        }
        st[node].lazyset = -1;
        st[node].lazyadd = 0;
    }
    else if (st[node].lazyadd != 0) {
        st[left].lazyadd += st[node].lazyadd;
        st[right].lazyadd += st[node].lazyadd;
        st[node].valuel += st[node].lazyadd;
        st[node].valuer += st[node].lazyadd;
        st[node].lazyadd = 0;
    }
}
void update(int node, int l, int r, int val) {
    if (st[node].left == -1) {
        st[node].left = ++ cnt;
        st[cnt] = Node();
    }
    if (st[node].right == -1) {
        st[node].right = ++ cnt;
        st[cnt] = Node();
    }
    //cout << ' ' << l << ' ' << r << ' ' << st[node].lazyset << endl;
    push(node, l, r);
    long long vall = st[node].valuel, valr = st[node].valuer;
    //cout << ' ' << l << ' ' << r << ' ' << vall << ' ' << valr << ' ' << val << endl;

    if (val >= 0 && vall + val > l && valr + val > r) { // all the boxes with cap inbetween l and r are set to equal the cap
        st[node].lazyadd = 0;
        st[node].lazyset = 1;
        push(node, l, r);
        return;
    }

    if (val >= 0 && vall + val <= l && valr + val <= r) { // all the boxes with cap inbetween l and r are added val
        st[node].lazyadd = val;
        push(node, l, r);
        return;
    }

    if (val < 0 && vall + val < 0 && valr + val < 0) { // all the boxes with cap inbetween l and r are set to equal the 0
        st[node].lazyadd = 0;
        st[node].lazyset = 0;
        push(node, l, r);
        return;
    }

    if (val < 0 && vall + val >= 0 && valr + val >= 0) { // all the boxes with cap inbetween l and r are added val
        st[node].lazyadd = val;
        push(node, l, r);
        return;
    }

    int mid = (l + r) / 2;

    int left = st[node].left, right = st[node].right;
    update(left, l, mid, val);
    update(right, mid + 1, r, val);
    st[node].valuel = st[left].valuel;
    st[node].valuer = st[right].valuer;
}

int query(int node, int l, int r, int x) {
    if (st[node].left == -1) {
        st[node].left = ++ cnt;
        st[cnt] = Node();
    }
    if (st[node].right == -1) {
        st[node].right = ++ cnt;
        st[cnt] = Node();
    }
    push(node, l, r);
    if (l == x && r == x) return st[node].valuel;
    int mid = (l + r) / 2;
    if (x <= mid) return query(st[node].left, l, mid, x);
    return query(st[node].right, mid + 1, r, x);
}

vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
                                    std::vector<int> r, std::vector<int> v) {
    int n = c.size();
    st[0] = Node();
    for (auto x : v) update(0, 1, 1e9, x);
    vector<int> s(n);
    for (int i = 0; i < n; i ++) {
        //cout << ' ' << c[i] << endl;
        s[i] = query(0, 1, 1e9, c[i]);
    }
    return s;
}

/*
3
10 15 13
2
0 2 20
0 2 -11
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 438 ms 1291860 KB Output is correct
2 Incorrect 436 ms 1291936 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 636 ms 1302868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 474 ms 1291856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 477 ms 1291860 KB Output is correct
2 Correct 477 ms 1291948 KB Output is correct
3 Correct 673 ms 1298968 KB Output is correct
4 Correct 557 ms 1295684 KB Output is correct
5 Correct 671 ms 1302136 KB Output is correct
6 Correct 782 ms 1302464 KB Output is correct
7 Correct 830 ms 1302828 KB Output is correct
8 Correct 680 ms 1302428 KB Output is correct
9 Correct 692 ms 1303972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 438 ms 1291860 KB Output is correct
2 Incorrect 436 ms 1291936 KB Output isn't correct
3 Halted 0 ms 0 KB -