QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#130760#1878. No Rest for the WickedjrjyyWA 1ms3580kbC++202.8kb2023-07-24 23:05:482023-07-24 23:05:49

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-24 23:05:49]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3580kb
  • [2023-07-24 23:05:48]
  • 提交

answer

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

using i64 = long long;

struct DSU {
    int n; std::vector<int> fa, dep, s;
    std::vector<std::pair<int *, int>> stk;
    DSU(const std::vector<int> &s_) : n(int(s_.size())), fa(n), dep(n), s(s_) {
        std::iota(fa.begin(), fa.end(), 0);
    }
    int find(int x) { return fa[x] == x ? x : find(fa[x]); }
    void set(int &x, int y) { stk.push_back({&x, x}), x = y; }
    void merge(int x, int y) {
        if ((x = find(x)) == (y = find(y))) return;
        if (dep[x] < dep[y]) std::swap(x, y);
        if (dep[x] == dep[y]) set(dep[x], dep[x] + 1);
        set(fa[y], x), set(s[x], std::max(s[x], s[y]));
    }
    void enter() { stk.push_back({nullptr, -1}); }
    void leave() {
        while (true) {
            auto [x, y] = stk.back(); stk.pop_back();
            if (!x) break;
            *x = y;
        }
    }
};

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

    int n, m; std::cin >> n >> m;
    std::vector<int> c(n), t(n), s(n);
    for (int i = 0; i < n; ++i) std::cin >> c[i] >> t[i] >> s[i];
    std::vector<std::pair<int, int>> e(m);
    for (auto &[u, v] : e) {
        std::cin >> u >> v, --u, --v;
        if (c[u] > c[v]) std::swap(u, v);
    }

    auto a = c; a.insert(a.end(), t.begin(), t.end());
    std::sort(a.begin(), a.end()), a.erase(std::unique(a.begin(), a.end()), a.end());
    for (auto &x : c) x = std::lower_bound(a.begin(), a.end(), x) - a.begin();
    for (auto &x : t) x = std::lower_bound(a.begin(), a.end(), x) - a.begin();
    const int k = int(a.size());

    std::vector<std::vector<int>> bel(k); for (int i = 0; i < n; ++i) bel[c[i]].push_back(i);
    auto ans = s; DSU dsu(s);
    auto solve = [&](auto self, int l, int r, auto two, auto one) -> void {
        dsu.enter();
        decltype(e) ntwo, none;
        for (auto [u, v] : two) {
            int ql = c[v], qr = std::min(t[u], t[v]) + 1;
            if (ql <= l && r <= qr) {
                dsu.merge(u, v);
            } else if (!(r <= ql || qr <= l)) {
                ntwo.push_back({u, v});
            }
        }
        for (auto [u, v] : one) {
            int ql = c[u], qr = std::min(c[v], t[u] + 1);
            if (ql <= l && r <= qr) {
                ans[u] = std::max(ans[u], ans[v]);
            } else if (!(r <= ql || qr <= l)) {
                none.push_back({u, v});
            }
        }
        if (r - l == 1) {
            for (auto x : bel[l]) ans[x] = std::max(ans[x], dsu.s[dsu.find(x)]);
        } else {
            int m = (l + r) / 2;
            self(self, m, r, ntwo, none);
            self(self, l, m, ntwo, none);
        }
        dsu.leave();
    };
    solve(solve, 0, k, e, e);

    for (auto x : ans) std::cout << x << ' ';

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3460kb

input:

4 3
2 3 1
1 1 4
1 2 2
1 1 3
1 2
1 3
1 4

output:

2 4 2 3 

result:

ok 4 number(s): "2 4 2 3"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3572kb

input:

1 0
138088047 507565360 682493255

output:

682493255 

result:

ok 1 number(s): "682493255"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3580kb

input:

4 4
1 4 3
2 4 2
2 4 3
3 4 4
1 2
1 3
2 3
3 4

output:

4 3 4 4 

result:

wrong answer 2nd numbers differ - expected: '4', found: '3'