답안 #566448

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
566448 2022-05-22T10:18:18 Z elazarkoren 늑대인간 (IOI18_werewolf) C++17
15 / 100
296 ms 524288 KB
#include <bits/stdc++.h>
#include "werewolf.h"
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;

const int MAX_N = 2e5 + 5;


struct Dsu {
    int n;
    vector<bitset<MAX_N>> component;
    vi loga;
    vi par, t;
    vvi dp;
    Dsu() {}
    Dsu(int n): n(n) {
        component.resize(n), par.resize(n), t.resize(n);
        dp.resize(1, vi(n));
        for (int i = 0; i < n; i++) dp[0][i] = i, component[i][i] = true;
        iota(all(par), 0);
    }
    inline void Add(int time) {
        component.push_back(bitset<MAX_N>());
        par.push_back(n);
        t.push_back(time);
        dp[0].push_back(n);
        n++;
    }
    int Find(int i) {
        return par[i] == i ? i : par[i] = Find(par[i]);
    }
    void Union(int a, int b, int time) {
        int pa = Find(a), pb = Find(b);
        if (pa == pb) return;
        Add(time);
        par[pa] = par[pb] = n - 1;
        dp[0][pa] = dp[0][pb] = n - 1;
        component[n - 1] = component[pa] | component[pb];
    }
    void Build() {
        loga.resize(n + 1);
        for (int i = 2; i <= n; i++) loga[i] = loga[i >> 1] + 1;
        dp.resize(loga[n] + 1, vi(n));
        for (int i = n - 1; i >= 0; i--) {
            for (int j = 1; j <= loga[n]; j++) {
                dp[j][i] = dp[j - 1][dp[j - 1][i]];
            }
        }
    }
    int Jump(int node, int time) {
        for (int i = loga[n]; i >= 0; i--) {
            if (t[dp[i][node]] <= time) {
                node = dp[i][node];
            }
        }
        return node;
    }
};

int ind[MAX_N];

vi check_validity(int n, vi x, vi y, vi s, vi e, vi l, vi r) {
    int m = x.size();
    Dsu d_min(n), d_max(n);
    iota(ind, ind + m, 0);
    sort(ind, ind + m, [&] (int i, int j) {
        return max(x[i], y[i]) < max(x[j], y[j]);
    });
    for (int i = 0; i < m; i++) {
        d_min.Union(x[ind[i]], y[ind[i]], max(x[ind[i]], y[ind[i]]));
    }
    d_min.Build();
    sort(ind, ind + m, [&] (int i, int j) {
        return min(x[i], y[i]) > min(x[j], y[j]);
    });
    for (int i = 0; i < m; i++) {
        d_max.Union(x[ind[i]], y[ind[i]], n - min(x[ind[i]], y[ind[i]]));
    }
    d_max.Build();
    int q = s.size();
    vi ans(q);
    for (int i = 0; i < q; i++) {
        int time_max = n - l[i], time_min = r[i];
        int v_max = d_max.Jump(s[i], time_max);
        int v_min = d_min.Jump(e[i], time_min);
        ans[i] = (d_min.component[v_min] & d_max.component[v_max]).any();
    }
    return ans;
}
//6 6 3
//0 3
//1 2
//1 5
//1 3
//2 5
//3 4
//
//4 2 1 2
//4 2 2 2
//5 4 3 4

//6 5 3
//1 3
//3 0
//0 4
//4 5
//5 2
//
//3 5 0 5
//2 1 0 4
//4 2 3 4
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 10184 KB Output is correct
2 Correct 9 ms 10056 KB Output is correct
3 Correct 3 ms 2384 KB Output is correct
4 Correct 1 ms 936 KB Output is correct
5 Correct 9 ms 10184 KB Output is correct
6 Correct 9 ms 10056 KB Output is correct
7 Correct 9 ms 10184 KB Output is correct
8 Correct 9 ms 10184 KB Output is correct
9 Correct 8 ms 10184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 10184 KB Output is correct
2 Correct 9 ms 10056 KB Output is correct
3 Correct 3 ms 2384 KB Output is correct
4 Correct 1 ms 936 KB Output is correct
5 Correct 9 ms 10184 KB Output is correct
6 Correct 9 ms 10056 KB Output is correct
7 Correct 9 ms 10184 KB Output is correct
8 Correct 9 ms 10184 KB Output is correct
9 Correct 8 ms 10184 KB Output is correct
10 Correct 241 ms 295008 KB Output is correct
11 Correct 230 ms 294880 KB Output is correct
12 Correct 224 ms 294904 KB Output is correct
13 Correct 228 ms 294940 KB Output is correct
14 Correct 250 ms 294928 KB Output is correct
15 Correct 216 ms 295108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 296 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 10184 KB Output is correct
2 Correct 9 ms 10056 KB Output is correct
3 Correct 3 ms 2384 KB Output is correct
4 Correct 1 ms 936 KB Output is correct
5 Correct 9 ms 10184 KB Output is correct
6 Correct 9 ms 10056 KB Output is correct
7 Correct 9 ms 10184 KB Output is correct
8 Correct 9 ms 10184 KB Output is correct
9 Correct 8 ms 10184 KB Output is correct
10 Correct 241 ms 295008 KB Output is correct
11 Correct 230 ms 294880 KB Output is correct
12 Correct 224 ms 294904 KB Output is correct
13 Correct 228 ms 294940 KB Output is correct
14 Correct 250 ms 294928 KB Output is correct
15 Correct 216 ms 295108 KB Output is correct
16 Runtime error 296 ms 524288 KB Execution killed with signal 9
17 Halted 0 ms 0 KB -