답안 #766111

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
766111 2023-06-25T10:22:37 Z tengiz05 늑대인간 (IOI18_werewolf) C++17
7 / 100
468 ms 178096 KB
#include "werewolf.h"
#include "iostream"
#include "array"
#include "queue"
#include "bitset"
#include "algorithm"
#ifndef EVAL
#include "grader.cpp"
#endif
using namespace std;

constexpr int B = 300;

struct DSUmin {
    int n;
    vector<int> p;
    DSUmin(int n) : n(n), p(n) { for (int i = 0; i < n; i++) p[i] = i; }
    int leader(int u) {
        while (u != p[u]) u = p[u] = p[p[u]];
        return u;
    }
    void merge(int u, int v) {
        u = leader(u);
        v = leader(v);
        if (u == v) return;
        p[v] = u;
    }
};
struct DSUbit {
    int n;
    vector<int> p, siz;
    vector<bitset<670>> f;
    DSUbit(int n) : n(n), p(n), siz(n, 1), f(n) { for (int i = 0; i < n; i++) p[i] = i; }
    int leader(int u) {
        while (u != p[u]) u = p[u] = p[p[u]];
        return u;
    }
    void merge(int u, int v) {
        u = leader(u);
        v = leader(v);
        if (u == v) return;
        if (siz[v] > siz[u]) swap(u, v);
        f[u] |= f[v];
        siz[u] += siz[v];
        p[v] = u;
    }
};

std::vector<int> Min;
std::vector<int> block;

struct DSU {
    int n;
    vector<int> p, siz;
    vector<vector<int>> f, bf;
    DSU(int n) : n(n), p(n), siz(n), f(n), bf(n) {
        for (int i = 0; i < n; i++) {
            siz[i] = 1;
            p[i] = i;
            f[i].push_back(i);
        }
    }
    int leader(int u) {
        while (u != p[u]) u = p[u] = p[p[u]];
        return u;
    }
    void merge(int u, int v) {
        u = leader(u);
        v = leader(v);
        if (u == v) return;
        if (siz[v] > siz[u]) swap(u, v);
        for (int x : f[v]) {
            f[u].push_back(x);
        }
        for (int x : bf[v]) {
            bf[u].push_back(x);
        }
        f[v].clear();
        f[v].shrink_to_fit();
        bf[v].clear();
        bf[v].shrink_to_fit();
        siz[u] += siz[v];
        p[v] = u;
        if (f[u].size() >= B) {
            for (int i = 0; i < B; i++) {
                block[f[u].back()] = Min.size();
                f[u].pop_back();
            }
            bf[u].push_back(Min.size());
            Min.push_back(n);
        }
    }
};

std::vector<int> check_validity(int n, std::vector<int> X, std::vector<int> Y,
                                std::vector<int> S, std::vector<int> E,
                                std::vector<int> L, std::vector<int> R) {
    int m = X.size();
    vector<vector<int>> e(n);
    for (int i = 0; i < m; i++) {
        e[X[i]].push_back(Y[i]);
        e[Y[i]].push_back(X[i]);
    }
    int Q = S.size();
    vector<int> ans(Q);
    vector<vector<array<int, 4>>> q(n);
    for (int i = 0; i < Q; i++) {
        q[R[i]].push_back({i, S[i], E[i], L[i]});
    }
    DSU dsu(n);
    block.assign(n, -1);
    vector<vector<array<int, 3>>> nq(n), bq(n);
    for (int i = 0; i < n; i++) {
        for (int j : e[i]) {
            if (j < i) {
                dsu.merge(i, j);
            }
        }
        for (auto [id, s, t, L] : q[i]) {
            for (int x : dsu.f[dsu.leader(t)]) {
                nq[L].push_back({id, s, x});
            }
            for (int x : dsu.bf[dsu.leader(t)]) {
                bq[L].push_back({id, s, x});
            }
        }
    }
    DSUmin fastdsu(n);
    DSUbit bitdsu(n);
    for (int i = 0; i < n; i++) {
        if (block[i] != -1) {
            bitdsu.f[i][block[i]] = 1;
        }
    }
    for (int i = n - 1; i >= 0; i--) {
        for (int j : e[i]) {
            if (j > i) {
                fastdsu.merge(i, j);
            }
        }
        for (auto [id, s, x] : nq[i]) {
            if (fastdsu.leader(x) == fastdsu.leader(s)) {
                ans[id] = 1;
            }
        }
        for (auto [id, s, x] : bq[i]) {
            if (bitdsu.f[bitdsu.leader(s)][x]) {
                ans[id] = 1;
            }
        }
    }
    return ans;
}

/*


6 6 3
5 1
1 2
1 3
3 4
3 0
5 2
4 2 1 2
4 2 2 2
5 4 3 4



*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Incorrect 12 ms 7380 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 468 ms 178096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Incorrect 12 ms 7380 KB Output isn't correct
11 Halted 0 ms 0 KB -