답안 #1099827

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099827 2024-10-12T05:31:10 Z model_code 트리 (IOI24_tree) C++17
22 / 100
92 ms 26396 KB
// incorrect/endagorion-L1.cpp

#include "tree.h"
#include <bits/stdc++.h>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 310000;

i64 ans[maxn];
int n;
int p[maxn];
i64 w[maxn];
vi e[maxn];

int par[maxn], nleaves[maxn], tcr[maxn];
i64 sl[maxn];

int root(int v) {
    return v == par[v] ? v : par[v] = root(par[v]);
}

void init(vi P, vi W) {
    n = sz(P);
    copy(all(P), p);
    copy(all(W), w);
    forn(i, n) e[i].clear();
    for1(i, n - 1) e[P[i]].pb(i);

    vi ord(n);
    iota(all(ord), 0);
    sort(rall(ord), [&](int i, int j){return w[i] < w[j];});

    iota(par, par + n, 0);
    fill(nleaves, nleaves + n, 1);
    fill(tcr, tcr + n, n + 1);
    fill(sl, sl + n + 1, 0);
    i64 v0 = 0;

    for (int v: ord) {
        if (e[v].empty()) {
            v0 += w[v];
            continue;
        }
        int r = root(v);
        sl[nleaves[r]] += tcr[r] - w[v];
        --nleaves[r];
        tcr[r] = w[v];
        for (int u: e[v]) {
            sl[nleaves[u]] += tcr[u] - w[v];
            par[u] = r;
            nleaves[r] += nleaves[u];
        }
    }
    sl[nleaves[0]] += tcr[0];
//    for1(i, n) if (sl[i]) cerr << i << ' ' << sl[i] << '\n';
    i64 slope = 0, v = v0;
    ford(i, n + 1) {
        v += slope;
        ans[i] = v;
        slope += sl[i];
    }
}

i64 query(int L, int R) {
    if (R >= n) return ans[n];
	return ans[R];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 23500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 7768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 7768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 58 ms 24280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 58 ms 24280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 23512 KB Output is correct
2 Correct 85 ms 22572 KB Output is correct
3 Correct 88 ms 24140 KB Output is correct
4 Correct 83 ms 24140 KB Output is correct
5 Correct 84 ms 24148 KB Output is correct
6 Correct 78 ms 24140 KB Output is correct
7 Correct 81 ms 23888 KB Output is correct
8 Correct 79 ms 26396 KB Output is correct
9 Correct 81 ms 23372 KB Output is correct
10 Correct 92 ms 23372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7512 KB Output is correct
2 Incorrect 46 ms 23500 KB Output isn't correct
3 Halted 0 ms 0 KB -