답안 #1110995

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110995 2024-11-11T09:06:46 Z crafticat Magic Tree (CEOI19_magictree) C++17
55 / 100
114 ms 37192 KB
#include <bits/stdc++.h>

using namespace std;

template<typename T>
using V = vector<T>;
using vi = V<int>;
using vb = V<bool>;
using pi = pair<int,int>;

#define F0R(i,n) for (int i = 0; i < n;i++)
#define FOR(i, j, n) for(int i = j; i < n;i++)
#define ckmin(x,y) x = min(x,y)
#define f first
#define s second
using ll = long long;
constexpr int INF = 1e9 + 5;

struct STL {
    vi pointers;
    V<multiset<pi>> gradients;

    STL(int n) {
        pointers.resize(n);
        gradients.resize(n);
        for (int i = 0; i < n;i++) {
            pointers[i] = i;
        }
    }

    void merge(int x, int y) {
        int pX = pointers[x], pY = pointers[y];
        if (gradients[pY].size() > gradients[pX].size()) swap(pX,pY);

        pointers[y] = pX;
        pointers[x] = pX;

        for (auto elm : gradients[pY]) {
            gradients[pX].insert(elm);
        }
    }

    void insert(int x, int t, int v) {
        x = pointers[x];

        int sum = 0;
        while (true) {
            auto it = gradients[x].upper_bound({t, INF});
            if (it == gradients[x].end()) break;

            int t1 = it->first;
            sum += it->second;
            gradients[x].erase(it);

            if (sum > v) {
                sum -= v;
                gradients[x].insert({t1, sum});
                break;
            }
        }

        gradients[x].insert({t,v});
    }
    int query(int x) {
        x = pointers[x];

        int sum = 0;
        for (auto [v,y] : gradients[x]) {
            sum += y;
        }
        return sum;
    }
};

V<pi> dat;
V<vi> g;
STL *stl;

void solve(int x, int p) {
    for (auto y : g[x]) {
        if (y == p) continue;
        solve(y, x);
        stl->merge(x, y);
    }
    stl->insert(x, dat[x].f, dat[x].s);
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, m, k; cin >> n >> m >> k;
    g.resize(n + 1);
    stl = new STL(n + 1);

    FOR(i, 2, n + 1) {
        int p; cin >> p;
        g[p].push_back(i);
        g[i].push_back(p);
    }

    dat.resize(n + 1);
    F0R(i, m) {
        int v, t, p; cin >> v >> t >> p;
        dat[v] = {t, p};
    }

    solve(1, -1);
    cout << stl->query(1);

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 107 ms 37192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 2 ms 764 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 57 ms 29288 KB Output is correct
5 Correct 69 ms 34064 KB Output is correct
6 Correct 74 ms 29200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 114 ms 34048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 84 ms 30864 KB Output is correct
11 Correct 82 ms 31480 KB Output is correct
12 Correct 66 ms 22600 KB Output is correct
13 Correct 59 ms 22600 KB Output is correct
14 Correct 78 ms 29512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 7004 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 764 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 57 ms 29288 KB Output is correct
14 Correct 69 ms 34064 KB Output is correct
15 Correct 74 ms 29200 KB Output is correct
16 Correct 84 ms 30864 KB Output is correct
17 Correct 82 ms 31480 KB Output is correct
18 Correct 66 ms 22600 KB Output is correct
19 Correct 59 ms 22600 KB Output is correct
20 Correct 78 ms 29512 KB Output is correct
21 Correct 16 ms 5968 KB Output is correct
22 Correct 102 ms 34632 KB Output is correct
23 Correct 87 ms 34632 KB Output is correct
24 Correct 101 ms 31048 KB Output is correct
25 Correct 62 ms 22820 KB Output is correct
26 Correct 99 ms 24144 KB Output is correct
27 Correct 87 ms 22340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Incorrect 107 ms 37192 KB Output isn't correct
11 Halted 0 ms 0 KB -