QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#325527#946. Magic TreeCamillus#Compile Error//C++203.4kb2024-02-11 16:16:462024-07-04 03:23:32

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 03:23:32]
  • 评测
  • [2024-02-11 16:16:46]
  • 提交

answer

/// @author Camillus <3
#include "bits/stdc++.h"

using ll = long long;
using namespace std;

int p[100500];
vector<int> g[100500];
int h[100500];

int sz[100500];
void dfs_sz(int u) {
    sz[u] = 1;
    for (int& v : g[u]) {
        dfs_sz(v);
        sz[u] += sz[v];
    }
}

void dfs_h(int u) {
    if (!g[u].empty()) {
        for (int v : g[u]) {
            h[v] = v;
        }
        h[g[u].front()] = h[u];
    }

    for (int v : g[u]) {
        dfs_h(v);
    }
}

pair<int, int> f[100500];

struct ds {
    vector<int> keys = {0};
    ds() {}

    void add_key(int day) {
        keys.push_back(day);
    }

    vector<ll> tree;
    int n;

    void build() {
        ranges::sort(keys);
        keys.erase(unique(keys.begin(), keys.end()), keys.end());
        n = (int)keys.size();
        tree.resize(n + 1);
    }

    int lower_bound(int key) {
        auto i = ranges::lower_bound(keys, key) - keys.begin();
        return i;
    }

    int upper_bound(int key) {
        auto i = ranges::lower_bound(keys, key) - keys.begin();
        return i;
    }

    void add(int l, int r, ll v) {
        for (int i = l; i < n; i += i & -i) {
            tree[i] += v;
        }

        for (int i = r + 1; i < n; i += i & -i) {
            tree[i] -= v;
        }
    }

    ll get(int i) const {
        ll res = 0;
        for (; i > 0; i -= i & -i) {
            res += tree[i];
        }
        return res;
    }
};

ds DS[100500];
void make_ds(int n) {
    for (int u = 1; u <= n; u++) {
        if (h[u] == u) {
            auto dfs = [&r=u](auto &&dfs, int u) -> void {
                if (f[u].first) {
                    debug(r, u);
                    DS[r].add_key(f[u].first);
                }
                for (int v : g[u]) {
                    dfs(dfs, v);
                }
            };
            dfs(dfs, u);
            DS[u].build();
            debug(u);
            debug(DS[u].keys);
        }
    }
}

void dfs(int u) {
    for (int v : g[u]) {
        dfs(v);

        if (v != g[u].front()) {
            for (int i = 1; i < DS[v].n; i++) {
                int L = DS[v].keys[i];
                int R = 2'000'000'000;
                if (i + 1 != DS[v].n) {
                    R = DS[v].keys[i + 1];
                }

                ll D = DS[v].get(i);

                L = DS[h[u]].lower_bound(L);
                R = DS[h[u]].lower_bound(R);

                DS[h[u]].add(L, R - 1, D);
            }
        }
    }

    if (f[u].first != 0) {
        int i = DS[h[u]].lower_bound(f[u].first);
        ll value = DS[h[u]].get(i) + f[u].second;

        for (; i < DS[h[u]].n; i++) {
            ll cur = DS[h[u]].get(i);
            if (cur < value) {
                DS[h[u]].add(i, i, value - cur);
            } else {
                break;
            }
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    h[1] = 1;

    int n, m, k;
    cin >> n >> m >> k;

    for (int u = 2; u <= n; u++) {
        cin >> p[u];
        g[p[u]].push_back(u);
    }

    for (int i = 0; i < m; i++) {
        int u, d, w;
        cin >> u >> d >> w;

        f[u] = {d, w};
    }

    dfs_sz(1);
    dfs_h(1);
    make_ds(n);
    dfs(1);

    cout << DS[1].get(DS[1].n - 1) << '\n';
    return 0;
}

详细

answer.code: In lambda function:
answer.code:88:21: error: there are no arguments to ‘debug’ that depend on a template parameter, so a declaration of ‘debug’ must be available [-fpermissive]
   88 |                     debug(r, u);
      |                     ^~~~~
answer.code:88:21: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
answer.code: In function ‘void make_ds(int)’:
answer.code:97:13: error: ‘debug’ was not declared in this scope
   97 |             debug(u);
      |             ^~~~~
answer.code: In instantiation of ‘make_ds(int)::<lambda(auto:54&&, int)> [with auto:54 = make_ds(int)::<lambda(auto:54&&, int)>&]’:
answer.code:95:16:   required from here
answer.code:88:26: error: ‘debug’ was not declared in this scope
   88 |                     debug(r, u);
      |                     ~~~~~^~~~~~