Submission #779477

# Submission time Handle Problem Language Result Execution time Memory
779477 2023-07-11T13:11:01 Z t6twotwo Werewolf (IOI18_werewolf) C++17
100 / 100
694 ms 115152 KB
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
int N, timer;
vector<int> a[2], l[2], r[2], p[2];
vector<vector<int>> adj[2], ch[2];
void dfs(int z, int x) {
    l[z][x] = timer;
    for (int y : ch[z][x]) {
        dfs(z, y);
    }
    r[z][x] = ++timer;
    a[z].push_back(x);
}
void build(int z) {
    p[z].resize(N, N);
    l[z].resize(N);
    r[z].resize(N);
    ch[z].resize(N);
    vector<int> par(N);
    iota(par.begin(), par.end(), 0);
    function<int(int)> find = [&](int x) {
        return x == par[x] ? x : par[x] = find(par[x]);
    };
    for (int i = 0; i < N; i++) {
        for (int j : adj[z][i]) {
            if (j < i) {
                int x = find(j);
                if (x != i) {
                    ch[z][i].push_back(x);
                    p[z][x] = par[x] = i;
                }
            }
        }
    }
    timer = 0;
    dfs(z, N - 1);
}
vector<int> check_validity(int n, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) {
    N = n;
    adj[0].resize(N);
    adj[1].resize(N);
    for (int i = 0; i < X.size(); i++) {
        adj[0][X[i]].push_back(Y[i]);
        adj[0][Y[i]].push_back(X[i]);
        X[i] = N - 1 - X[i];
        Y[i] = N - 1 - Y[i];
        adj[1][X[i]].push_back(Y[i]);
        adj[1][Y[i]].push_back(X[i]);
    }
    build(0);
    build(1);
    for (int i = 0; i < N; i++) {
        a[1][i] = N - 1 - a[1][i];
        p[1][i] = N - 1 - p[1][i];
        for (int &x : ch[1][i]) {
            x = N - 1 - x;
        }
    }
    for (int i = 0; i < N / 2; i++) {
        swap(p[1][i], p[1][N - 1 - i]);
        swap(l[1][i], l[1][N - 1 - i]);
        swap(r[1][i], r[1][N - 1 - i]);
        swap(ch[1][i], ch[1][N - 1 - i]);
    }
    int par[2][N][18];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 18; j++) {
            par[0][i][j] = N;
            par[1][i][j] = -1;
        }
    }
    for (int i = N - 1; i >= 0; i--) {
        par[0][i][0] = p[0][i];
        for (int j = 0; j < 17 && par[0][i][j] != N; j++) {
            par[0][i][j + 1] = par[0][par[0][i][j]][j];
        }
    }
    for (int i = 0; i < N; i++) {
        par[1][i][0] = p[1][i];
        for (int j = 0; j < 17 && par[1][i][j] != -1; j++) {
            par[1][i][j + 1] = par[1][par[1][i][j]][j];
        }
    }
    int Q = S.size();
    vector<int> ans(Q), L0(Q), R0(Q), L1(Q), R1(Q);
    vector<vector<int>> T(N);
    for (int i = 0; i < Q; i++) {
        int t[2];
        t[0] = E[i];
        for (int j = 17; j >= 0; j--) {
            if (par[0][t[0]][j] <= R[i]) {
                t[0] = par[0][t[0]][j];
            }
        }
        t[1] = S[i];
        for (int j = 17; j >= 0; j--) {
            if (par[1][t[1]][j] >= L[i]) {
                t[1] = par[1][t[1]][j];
            }
        }
        L0[i] = l[0][t[0]];
        R0[i] = r[0][t[0]];
        L1[i] = l[1][t[1]];
        R1[i] = r[1][t[1]];
        T[R1[i] - 1].push_back(i);
    }
    vector<int> b(N);
    for (int i = 0; i < N; i++) {
        b[a[0][i]] = i;
    }
    vector<int> st(2 * N, -1);
    for (int i = 0; i < N; i++) {
        int j = b[a[1][i]];
        for (st[j += N] = i; j /= 2;) {
            st[j] = max(st[j * 2], st[j * 2 + 1]);
        }
        for (int j : T[i]) {
            int k = -1, l = L0[j], r = R0[j];
            for (l += N, r += N; l < r; l /= 2, r /= 2) {
                if (l % 2 == 1) {
                    k = max(k, st[l++]);
                }
                if (r % 2 == 1) {
                    k = max(k, st[--r]);
                }
            }
            ans[j] = k >= L1[j];
        }
    }
    return ans;
}

Compilation message

werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int i = 0; i < X.size(); i++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 340 KB Output is correct
10 Correct 5 ms 1748 KB Output is correct
11 Correct 5 ms 1676 KB Output is correct
12 Correct 6 ms 1748 KB Output is correct
13 Correct 5 ms 1748 KB Output is correct
14 Correct 5 ms 1716 KB Output is correct
15 Correct 5 ms 1808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 507 ms 97764 KB Output is correct
2 Correct 492 ms 96200 KB Output is correct
3 Correct 520 ms 104540 KB Output is correct
4 Correct 451 ms 104616 KB Output is correct
5 Correct 430 ms 104888 KB Output is correct
6 Correct 470 ms 105648 KB Output is correct
7 Correct 485 ms 105040 KB Output is correct
8 Correct 431 ms 104624 KB Output is correct
9 Correct 486 ms 104324 KB Output is correct
10 Correct 434 ms 104312 KB Output is correct
11 Correct 381 ms 104272 KB Output is correct
12 Correct 364 ms 104144 KB Output is correct
13 Correct 574 ms 110352 KB Output is correct
14 Correct 633 ms 110400 KB Output is correct
15 Correct 597 ms 110256 KB Output is correct
16 Correct 622 ms 110416 KB Output is correct
17 Correct 463 ms 105008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 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 340 KB Output is correct
10 Correct 5 ms 1748 KB Output is correct
11 Correct 5 ms 1676 KB Output is correct
12 Correct 6 ms 1748 KB Output is correct
13 Correct 5 ms 1748 KB Output is correct
14 Correct 5 ms 1716 KB Output is correct
15 Correct 5 ms 1808 KB Output is correct
16 Correct 507 ms 97764 KB Output is correct
17 Correct 492 ms 96200 KB Output is correct
18 Correct 520 ms 104540 KB Output is correct
19 Correct 451 ms 104616 KB Output is correct
20 Correct 430 ms 104888 KB Output is correct
21 Correct 470 ms 105648 KB Output is correct
22 Correct 485 ms 105040 KB Output is correct
23 Correct 431 ms 104624 KB Output is correct
24 Correct 486 ms 104324 KB Output is correct
25 Correct 434 ms 104312 KB Output is correct
26 Correct 381 ms 104272 KB Output is correct
27 Correct 364 ms 104144 KB Output is correct
28 Correct 574 ms 110352 KB Output is correct
29 Correct 633 ms 110400 KB Output is correct
30 Correct 597 ms 110256 KB Output is correct
31 Correct 622 ms 110416 KB Output is correct
32 Correct 463 ms 105008 KB Output is correct
33 Correct 578 ms 106096 KB Output is correct
34 Correct 223 ms 41532 KB Output is correct
35 Correct 613 ms 107160 KB Output is correct
36 Correct 547 ms 106348 KB Output is correct
37 Correct 605 ms 106660 KB Output is correct
38 Correct 566 ms 106604 KB Output is correct
39 Correct 561 ms 107904 KB Output is correct
40 Correct 694 ms 115152 KB Output is correct
41 Correct 483 ms 105048 KB Output is correct
42 Correct 431 ms 104500 KB Output is correct
43 Correct 686 ms 110136 KB Output is correct
44 Correct 502 ms 105416 KB Output is correct
45 Correct 467 ms 106580 KB Output is correct
46 Correct 469 ms 105972 KB Output is correct
47 Correct 628 ms 110472 KB Output is correct
48 Correct 605 ms 110304 KB Output is correct
49 Correct 602 ms 110468 KB Output is correct
50 Correct 595 ms 110316 KB Output is correct
51 Correct 651 ms 114424 KB Output is correct
52 Correct 621 ms 114400 KB Output is correct