답안 #477659

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477659 2021-10-03T01:44:45 Z SirCovidThe19th 늑대인간 (IOI18_werewolf) C++17
100 / 100
872 ms 157344 KB
#include <bits/stdc++.h>
#include "werewolf.h"
using namespace std; 

#define vi vector<int>

const int mx = 6e5 + 5;

int par[mx], tin[mx], tout[mx], ti, id; vector<int> dsuAdj[mx]; set<int> nodes[mx];

int get(int i){ 
    return i == par[i] ? i : par[i] = get(par[i]); 
}
void merge(int a, int b, bool build){
    a = get(a); b = get(b); if (a == b) return;
    if (build){
        dsuAdj[id].push_back(a); dsuAdj[id].push_back(b);
        par[a] = par[b] = id++;
    }
    else{
        if (nodes[a].size() > nodes[b].size()) swap(a, b); 
        par[a] = b;
        nodes[b].insert(nodes[a].begin(), nodes[a].end());
    }
}
void dfs(int i){
    tin[i] = ti++;
    for (int x : dsuAdj[i]) dfs(x);
    tout[i] = ti - 1;
}

vi check_validity(int n, vi X, vi Y, vi S, vi E, vi L, vi R){
    int m = X.size(), q = L.size();  
    
    vi adj[n], QL[n], QR[n], st(q), ans(q);
    
    for (int i = 0; i < m; i++) adj[X[i]].push_back(Y[i]), adj[Y[i]].push_back(X[i]);
    for (int i = 0; i < q; i++) QL[L[i]].push_back(i), QR[R[i]].push_back(i);

    iota(par, par + n * 2, 0); id = n;
    for (int i = n - 1; ~i; i--){
        for (int x : adj[i]) if (x > i) merge(i, x, 1); 
        for (int qry : QL[i]) st[qry] = get(S[qry]);
    }
    
    dfs(id - 1); 
    for (int i = 0; i < n; i++) nodes[i].insert(tin[i]);
    
    iota(par, par + n * 2, 0);
    for (int i = 0; i < n; i++){
        for (int x : adj[i]) if (x < i) merge(i, x, 0);
        for (int qry : QR[i]){
            int cmp = get(E[qry]);
            auto it = nodes[cmp].lower_bound(tin[st[qry]]);
            if (it != nodes[cmp].end() and *it <= tout[st[qry]]) ans[qry] = 1;
        }
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 42572 KB Output is correct
2 Correct 21 ms 42616 KB Output is correct
3 Correct 23 ms 42572 KB Output is correct
4 Correct 25 ms 42572 KB Output is correct
5 Correct 24 ms 42600 KB Output is correct
6 Correct 22 ms 42508 KB Output is correct
7 Correct 24 ms 42540 KB Output is correct
8 Correct 23 ms 42572 KB Output is correct
9 Correct 23 ms 42592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 42572 KB Output is correct
2 Correct 21 ms 42616 KB Output is correct
3 Correct 23 ms 42572 KB Output is correct
4 Correct 25 ms 42572 KB Output is correct
5 Correct 24 ms 42600 KB Output is correct
6 Correct 22 ms 42508 KB Output is correct
7 Correct 24 ms 42540 KB Output is correct
8 Correct 23 ms 42572 KB Output is correct
9 Correct 23 ms 42592 KB Output is correct
10 Correct 30 ms 43660 KB Output is correct
11 Correct 36 ms 43748 KB Output is correct
12 Correct 30 ms 43980 KB Output is correct
13 Correct 31 ms 43596 KB Output is correct
14 Correct 28 ms 43592 KB Output is correct
15 Correct 29 ms 43852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 798 ms 157344 KB Output is correct
2 Correct 612 ms 115672 KB Output is correct
3 Correct 637 ms 120388 KB Output is correct
4 Correct 735 ms 128564 KB Output is correct
5 Correct 755 ms 130208 KB Output is correct
6 Correct 828 ms 136380 KB Output is correct
7 Correct 762 ms 156740 KB Output is correct
8 Correct 615 ms 115784 KB Output is correct
9 Correct 533 ms 119284 KB Output is correct
10 Correct 538 ms 127240 KB Output is correct
11 Correct 598 ms 128776 KB Output is correct
12 Correct 687 ms 136956 KB Output is correct
13 Correct 574 ms 117680 KB Output is correct
14 Correct 575 ms 117672 KB Output is correct
15 Correct 620 ms 117672 KB Output is correct
16 Correct 627 ms 117692 KB Output is correct
17 Correct 737 ms 156068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 42572 KB Output is correct
2 Correct 21 ms 42616 KB Output is correct
3 Correct 23 ms 42572 KB Output is correct
4 Correct 25 ms 42572 KB Output is correct
5 Correct 24 ms 42600 KB Output is correct
6 Correct 22 ms 42508 KB Output is correct
7 Correct 24 ms 42540 KB Output is correct
8 Correct 23 ms 42572 KB Output is correct
9 Correct 23 ms 42592 KB Output is correct
10 Correct 30 ms 43660 KB Output is correct
11 Correct 36 ms 43748 KB Output is correct
12 Correct 30 ms 43980 KB Output is correct
13 Correct 31 ms 43596 KB Output is correct
14 Correct 28 ms 43592 KB Output is correct
15 Correct 29 ms 43852 KB Output is correct
16 Correct 798 ms 157344 KB Output is correct
17 Correct 612 ms 115672 KB Output is correct
18 Correct 637 ms 120388 KB Output is correct
19 Correct 735 ms 128564 KB Output is correct
20 Correct 755 ms 130208 KB Output is correct
21 Correct 828 ms 136380 KB Output is correct
22 Correct 762 ms 156740 KB Output is correct
23 Correct 615 ms 115784 KB Output is correct
24 Correct 533 ms 119284 KB Output is correct
25 Correct 538 ms 127240 KB Output is correct
26 Correct 598 ms 128776 KB Output is correct
27 Correct 687 ms 136956 KB Output is correct
28 Correct 574 ms 117680 KB Output is correct
29 Correct 575 ms 117672 KB Output is correct
30 Correct 620 ms 117672 KB Output is correct
31 Correct 627 ms 117692 KB Output is correct
32 Correct 737 ms 156068 KB Output is correct
33 Correct 829 ms 127208 KB Output is correct
34 Correct 282 ms 65088 KB Output is correct
35 Correct 775 ms 120844 KB Output is correct
36 Correct 792 ms 130112 KB Output is correct
37 Correct 797 ms 121132 KB Output is correct
38 Correct 778 ms 126904 KB Output is correct
39 Correct 760 ms 110148 KB Output is correct
40 Correct 838 ms 123340 KB Output is correct
41 Correct 730 ms 122000 KB Output is correct
42 Correct 656 ms 128308 KB Output is correct
43 Correct 872 ms 121436 KB Output is correct
44 Correct 757 ms 121580 KB Output is correct
45 Correct 627 ms 109784 KB Output is correct
46 Correct 650 ms 109176 KB Output is correct
47 Correct 624 ms 117700 KB Output is correct
48 Correct 585 ms 117640 KB Output is correct
49 Correct 624 ms 117680 KB Output is correct
50 Correct 635 ms 117632 KB Output is correct
51 Correct 722 ms 121540 KB Output is correct
52 Correct 702 ms 121672 KB Output is correct