Submission #922478

# Submission time Handle Problem Language Result Execution time Memory
922478 2024-02-05T14:44:58 Z Alihan_8 Werewolf (IOI18_werewolf) C++17
100 / 100
972 ms 134992 KB
#include <bits/stdc++.h>

#include "werewolf.h"

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
//#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

vector<int> check_validity(int N, vector<int> X, vector<int> Y,
                vector<int> S, vector<int> E, vector<int> L, vector<int> R){

    vector <vector<int>> adj(N);
    for ( int i = 0; i < X.size(); i++ ){
        adj[X[i]].pb(Y[i]);
        adj[Y[i]].pb(X[i]);
    }
    int n = N;
    auto gen = [&](int s){
        vector <vector<int>> tree(n);
        vector <int> fa(n);
        iota(all(fa), 0);
        auto find = [&](auto find, int u) -> int{
            return fa[u] == u ? u : fa[u] = find(find, fa[u]);
        };
        auto unite = [&](int u, int v){
            u = find(find, u), v = find(find, v);
            if ( u == v ){
                return false;
            }
            if ( u * s > v * s ){
                swap(u, v);
            }
            fa[v] = u;
            tree[u].pb(v);
            return true;
        };
        auto rng = [&](int u){
            return u >= 0 && u < n;
        };
        for ( int i = (s > 0 ? n - 1 : 0); rng(i); i -= s ){
            for ( auto &j: adj[i] ){
                if ( i * s < j * s ){
                    unite(i, j);
                }
            }
        }
        return tree;
    };
    auto wa = gen(1), wb = gen(-1);
    vector <vector<int>> upA(20, vector <int> (n)), upB(20, vector <int> (n, n - 1));
    vector <int> tin(n), tout(n);
    int ct = 0;
    auto dfs_wa = [&](auto dfs_wa, int u, int p) -> void{
        upA[0][u] = p;
        tin[u] = ++ct;
        for ( auto &v: wa[u] ){
            dfs_wa(dfs_wa, v, u);
        } tout[u] = ct;
    };
    auto dfs_wb = [&](auto dfs_wb, int u, int p) -> void{
        upB[0][u] = p;
        for ( auto &v: wb[u] ){
            dfs_wb(dfs_wb, v, u);
        }
    };
    dfs_wa(dfs_wa, 0, 0);
    dfs_wb(dfs_wb, n - 1, n - 1);
    for ( int i = 1; i < 20; i++ ){
        for ( int j = 0; j < n; j++ ){
            upA[i][j] = upA[i - 1][upA[i - 1][j]];
            upB[i][j] = upB[i - 1][upB[i - 1][j]];
        }
    }
    vector <vector<ar<int,2>>> qu(n);
    for ( int i = 0; i < S.size(); i++ ){
        int u = S[i], v = E[i];
        for ( int j = 19; j >= 0; j-- ){
            if ( upA[j][u] >= L[i] ){
                u = upA[j][u];
            }
            if ( upB[j][v] <= R[i] ){
                v = upB[j][v];
            }
        }
        qu[v].pb({u, i});
    }
    int q = S.size();
    vector <int> ans(q);
    vector <set<int>> s(n);
    auto dfs = [&](auto dfs, int u) -> void{
        s[u].insert(tin[u]);
        for ( auto &v: wb[u] ){
            dfs(dfs, v);
            if ( s[u].size() < s[v].size() ){
                swap(s[u], s[v]);
            }
            for ( auto &x: s[v] ){
                s[u].insert(x);
            } s[v].clear();
        }
        for ( auto &[v, j]: qu[u] ){
            ans[j] = s[u].lower_bound(tin[v]) != s[u].upper_bound(tout[v]);
        }
    };
    dfs(dfs, n - 1);
    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:37:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for ( int i = 0; i < X.size(); i++ ){
      |                      ~~^~~~~~~~~~
werewolf.cpp:99:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |     for ( int i = 0; i < S.size(); i++ ){
      |                      ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 444 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 444 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 5 ms 2140 KB Output is correct
11 Correct 5 ms 1884 KB Output is correct
12 Correct 5 ms 1884 KB Output is correct
13 Correct 5 ms 2552 KB Output is correct
14 Correct 5 ms 2396 KB Output is correct
15 Correct 6 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 932 ms 111108 KB Output is correct
2 Correct 848 ms 115996 KB Output is correct
3 Correct 705 ms 109484 KB Output is correct
4 Correct 741 ms 107248 KB Output is correct
5 Correct 725 ms 107064 KB Output is correct
6 Correct 780 ms 107800 KB Output is correct
7 Correct 831 ms 110068 KB Output is correct
8 Correct 538 ms 116232 KB Output is correct
9 Correct 442 ms 109568 KB Output is correct
10 Correct 350 ms 106560 KB Output is correct
11 Correct 389 ms 106736 KB Output is correct
12 Correct 403 ms 107440 KB Output is correct
13 Correct 745 ms 128828 KB Output is correct
14 Correct 786 ms 128800 KB Output is correct
15 Correct 722 ms 128976 KB Output is correct
16 Correct 703 ms 129008 KB Output is correct
17 Correct 819 ms 109968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 444 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 5 ms 2140 KB Output is correct
11 Correct 5 ms 1884 KB Output is correct
12 Correct 5 ms 1884 KB Output is correct
13 Correct 5 ms 2552 KB Output is correct
14 Correct 5 ms 2396 KB Output is correct
15 Correct 6 ms 2140 KB Output is correct
16 Correct 932 ms 111108 KB Output is correct
17 Correct 848 ms 115996 KB Output is correct
18 Correct 705 ms 109484 KB Output is correct
19 Correct 741 ms 107248 KB Output is correct
20 Correct 725 ms 107064 KB Output is correct
21 Correct 780 ms 107800 KB Output is correct
22 Correct 831 ms 110068 KB Output is correct
23 Correct 538 ms 116232 KB Output is correct
24 Correct 442 ms 109568 KB Output is correct
25 Correct 350 ms 106560 KB Output is correct
26 Correct 389 ms 106736 KB Output is correct
27 Correct 403 ms 107440 KB Output is correct
28 Correct 745 ms 128828 KB Output is correct
29 Correct 786 ms 128800 KB Output is correct
30 Correct 722 ms 128976 KB Output is correct
31 Correct 703 ms 129008 KB Output is correct
32 Correct 819 ms 109968 KB Output is correct
33 Correct 840 ms 109600 KB Output is correct
34 Correct 198 ms 34232 KB Output is correct
35 Correct 874 ms 115456 KB Output is correct
36 Correct 838 ms 109124 KB Output is correct
37 Correct 945 ms 113728 KB Output is correct
38 Correct 908 ms 110528 KB Output is correct
39 Correct 972 ms 134220 KB Output is correct
40 Correct 630 ms 124296 KB Output is correct
41 Correct 455 ms 111428 KB Output is correct
42 Correct 434 ms 107652 KB Output is correct
43 Correct 699 ms 122944 KB Output is correct
44 Correct 820 ms 112844 KB Output is correct
45 Correct 691 ms 134992 KB Output is correct
46 Correct 705 ms 134812 KB Output is correct
47 Correct 870 ms 129132 KB Output is correct
48 Correct 816 ms 128896 KB Output is correct
49 Correct 712 ms 129116 KB Output is correct
50 Correct 718 ms 129120 KB Output is correct
51 Correct 475 ms 124168 KB Output is correct
52 Correct 480 ms 124608 KB Output is correct