QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#153206#6852. Escape The Mazejrjyy#WA 828ms376460kbC++202.5kb2023-08-29 17:02:462023-08-29 17:02:51

Judging History

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

  • [2023-08-29 17:02:51]
  • 评测
  • 测评结果:WA
  • 用时:828ms
  • 内存:376460kb
  • [2023-08-29 17:02:46]
  • 提交

answer

/* f.cpp */
#include <bits/stdc++.h>

using i64 = long long;
constexpr i64 V = 1.1e10, inf = 2e18;

struct Segment {
    i64 k = 0, b = inf;
    i64 operator()(i64 x) const {
        return k * x + b;
    }
};

struct Node {
    Node *l = nullptr, *r = nullptr;
    Segment s;
};
void modify(Node *&u, i64 l, i64 r, Segment x) {
    if (!u) {
        u = new Node{};
        u->s = x;
        return;
    }
    i64 m = (l + r) / 2;
    if (x(m) <= u->s(m)) {
        std::swap(x, u->s);
    }
    if (r - l == 1) {
        return;
    }
    if (x(l) <= u->s(l)) {
        modify(u->l, l, m, x);
    } else if (x(r - 1) <= u->s(r - 1)) {
        modify(u->r, m, r, x);
    }
}
void merge(Node *&u, Node *v, i64 l, i64 r) {
    if (!u) {
        u = v;
        return;
    }
    if (!v) {
        return;
    }
    modify(u, l, r, v->s);
    if (r - l == 1) {
        return;
    }
    i64 m = (l + r) / 2;
    merge(u->l, v->l, l, m);
    merge(u->r, v->r, m, r);
}
i64 query(Node *u, i64 l, i64 r, i64 p) {
    if (!u) {
        return inf;
    }
    i64 m = (l + r) / 2;
    if (p < m) {
        return std::min(u->s(p), query(u->l, l, m, p));
    } else {
        return std::min(u->s(p), query(u->r, m, r, p));
    }
}

void solve() {
    int n, L;
    std::cin >> n >> L;

    std::vector<std::vector<std::pair<int, int>>> adj(n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v, w;
        std::cin >> u >> v >> w;
        --u, --v;
        adj[u].emplace_back(v, w), adj[v].emplace_back(u, w);
    }

    std::vector<i64> dep(n), f(n);
    std::vector<Node *> root(n);
    auto dfs = [&](auto self, int u, int fa) -> void {
        root[u] = nullptr;
        for (auto [v, w] : adj[u]) if (v != fa) {
            dep[v] = dep[u] + w;
            self(self, v, u);
            merge(root[u], root[v], 0, V);
        }
        if (root[u]) {
            f[u] = query(root[u], 0, V, dep[u] + L) + (dep[u] + L) * (dep[u] + L);
        } else {
            f[u] = 0;
        }
        modify(root[u], 0, V, Segment{-2 * dep[u], f[u] + dep[u] * dep[u]});
    };

    int q;
    std::cin >> q;

    while (q--) {
        int x;
        std::cin >> x;
        --x;
        dep[x] = 0;
        dfs(dfs, x, -1);
        std::cout << f[x] << '\n';
    }
}

int main() {
    std::cin.tie(nullptr)->sync_with_stdio(false);

    int t;
    std::cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 828ms
memory: 376460kb

input:

5
6 -23131
2 1 -65179
3 2 -4529
4 3 869
5 4 -43646
6 3 72319
6
1
2
3
4
5
6
100000 -89702
2 1 90843
3 2 -51373
4 3 -37208
5 4 50738
6 4 -56753
7 2 -22185
8 6 -2522
9 5 6214
10 6 51682
11 2 97227
12 11 -72521
13 3 20844
14 9 -63596
15 1 -811
16 1 -63314
17 14 33366
18 11 -13974
19 5 82109
20 10 -35290...

output:

662650564
799985066
996865225
2147154145
2774444929
662650564
8045551809
8046090000
8049498961
8045013636
8046448804
8044834249
8046448804
8043040489
8042323041
8043937344
685706596
678810916
679957776
673558209
680844649
689587600
683090496
675480100
681157801
686754436
6434767089
6434767089
643428...

result:

wrong answer 2nd lines differ - expected: '584430625', found: '799985066'