답안 #75105

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
75105 2018-09-08T11:07:53 Z imeimi2000 늑대인간 (IOI18_werewolf) C++17
100 / 100
1058 ms 99236 KB
#include "werewolf.h"
#include <algorithm>

using namespace std;
typedef long long llong;

int n, m, q;
vector<int> edge[200000];

struct UF {
    int par[200000];
    UF() {
        for (int i = 0; i < 200000; ++i) par[i] = i;
    }
    int find(int x) {
        if (par[x] != x) return par[x] = find(par[x]);
        return x;
    }
} Luf, Ruf;

int Lpar[200000][20];
int Rpar[200000][20];
vector<int> Lchild[200000];
vector<int> Rchild[200000];

int Lst[200000];
int Led[200000];
int Rst[200000];
int Red[200000];
int LRd[200000];

void dfs(vector<int> child[], int st[], int ed[], int x, int &d) {
    st[x] = ++d;
    for (int i : child[x]) {
        dfs(child, st, ed, i, d);
    }
    ed[x] = d;
}

struct query {
    int i, t, x;
    query(int i, int t, int x) : i(i), t(t), x(x) {}
    bool operator<(const query &p) const {
        return t < p.t;
    }
};

int seg[200001];
void update(int i) {
    while (i <= n) {
        ++seg[i];
        i += i & -i;
    }
}

int sum(int i) {
    int ret = 0;
    while (i) {
        ret += seg[i];
        i -= i & -i;
    }
    return ret;
}

vector<int> check_validity(int N, vector<int> U, vector<int> V
                , vector<int> X, vector<int> Y, vector<int> L, vector<int> R) {
    n = N;
    m = U.size();
    q = X.size();
    for (int i = 0; i < m; ++i) {
        edge[U[i]].push_back(V[i]);
        edge[V[i]].push_back(U[i]);
    }
    for (int i = 0; i < n; ++i) Lpar[i][0] = 0;
    for (int i = n; i--; ) {
        for (int j : edge[i]) {
            if (j < i) continue;
            int x = Luf.find(i);
            int y = Luf.find(j);
            if (x == y) continue;
            Luf.par[y] = x;
            Lpar[y][0] = x;
            Lchild[x].push_back(y);
        }
    }
    
    for (int i = 0; i < n; ++i) Rpar[i][0] = n - 1;
    for (int i = 0; i < n; ++i) {
        for (int j : edge[i]) {
            if (i < j) continue;
            int x = Ruf.find(i);
            int y = Ruf.find(j);
            if (x == y) continue;
            Ruf.par[y] = x;
            Rpar[y][0] = x;
            Rchild[x].push_back(y);
        }
    }
    
    for (int i = 1; i < 20; ++i) {
        for (int j = 0; j < n; ++j) {
            Lpar[j][i] = Lpar[Lpar[j][i - 1]][i - 1];
            Rpar[j][i] = Rpar[Rpar[j][i - 1]][i - 1];
        }
    }
    
    int ord;
    ord = 0;
    dfs(Lchild, Lst, Led, Luf.find(0), ord);
    ord = 0;
    dfs(Rchild, Rst, Red, Ruf.find(0), ord);
    for (int i = 0; i < n; ++i) LRd[Lst[i] - 1] = Rst[i];
    
    vector<query> qs;
    for (int it = 0; it < q; ++it) {
        int x = X[it];
        int y = Y[it];
        int l = L[it];
        int r = R[it];
        for (int i = 20; i--; ) if (l <= Lpar[x][i]) x = Lpar[x][i];
        for (int i = 20; i--; ) if (Rpar[y][i] <= r) y = Rpar[y][i];
        qs.emplace_back(~it, Lst[x] - 1, y);
        qs.emplace_back(it, Led[x], y);
    }
    sort(qs.begin(), qs.end());
    vector<int> ret(q, 0);
    ord = 0;
    for (query i : qs) {
        while (ord < i.t) update(LRd[ord++]);
        int v = sum(Red[i.x]) - sum(Rst[i.x] - 1);
        if (i.i < 0) ret[~i.i] -= v;
        else ret[i.i] += v;
    }
    for (int &i : ret) i = (i > 0);
    return ret;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 16120 KB Output is correct
2 Correct 15 ms 16120 KB Output is correct
3 Correct 15 ms 16120 KB Output is correct
4 Correct 15 ms 16200 KB Output is correct
5 Correct 16 ms 16200 KB Output is correct
6 Correct 15 ms 16200 KB Output is correct
7 Correct 18 ms 16200 KB Output is correct
8 Correct 15 ms 16276 KB Output is correct
9 Correct 15 ms 16276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 16120 KB Output is correct
2 Correct 15 ms 16120 KB Output is correct
3 Correct 15 ms 16120 KB Output is correct
4 Correct 15 ms 16200 KB Output is correct
5 Correct 16 ms 16200 KB Output is correct
6 Correct 15 ms 16200 KB Output is correct
7 Correct 18 ms 16200 KB Output is correct
8 Correct 15 ms 16276 KB Output is correct
9 Correct 15 ms 16276 KB Output is correct
10 Correct 22 ms 17348 KB Output is correct
11 Correct 22 ms 17476 KB Output is correct
12 Correct 23 ms 17476 KB Output is correct
13 Correct 21 ms 17604 KB Output is correct
14 Correct 22 ms 17604 KB Output is correct
15 Correct 25 ms 17604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 771 ms 81892 KB Output is correct
2 Correct 746 ms 87720 KB Output is correct
3 Correct 693 ms 87720 KB Output is correct
4 Correct 674 ms 87720 KB Output is correct
5 Correct 746 ms 87720 KB Output is correct
6 Correct 743 ms 87720 KB Output is correct
7 Correct 835 ms 87720 KB Output is correct
8 Correct 754 ms 87880 KB Output is correct
9 Correct 661 ms 87880 KB Output is correct
10 Correct 615 ms 87880 KB Output is correct
11 Correct 649 ms 87880 KB Output is correct
12 Correct 632 ms 87880 KB Output is correct
13 Correct 808 ms 93944 KB Output is correct
14 Correct 836 ms 93944 KB Output is correct
15 Correct 898 ms 93972 KB Output is correct
16 Correct 889 ms 94080 KB Output is correct
17 Correct 754 ms 94080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 16120 KB Output is correct
2 Correct 15 ms 16120 KB Output is correct
3 Correct 15 ms 16120 KB Output is correct
4 Correct 15 ms 16200 KB Output is correct
5 Correct 16 ms 16200 KB Output is correct
6 Correct 15 ms 16200 KB Output is correct
7 Correct 18 ms 16200 KB Output is correct
8 Correct 15 ms 16276 KB Output is correct
9 Correct 15 ms 16276 KB Output is correct
10 Correct 22 ms 17348 KB Output is correct
11 Correct 22 ms 17476 KB Output is correct
12 Correct 23 ms 17476 KB Output is correct
13 Correct 21 ms 17604 KB Output is correct
14 Correct 22 ms 17604 KB Output is correct
15 Correct 25 ms 17604 KB Output is correct
16 Correct 771 ms 81892 KB Output is correct
17 Correct 746 ms 87720 KB Output is correct
18 Correct 693 ms 87720 KB Output is correct
19 Correct 674 ms 87720 KB Output is correct
20 Correct 746 ms 87720 KB Output is correct
21 Correct 743 ms 87720 KB Output is correct
22 Correct 835 ms 87720 KB Output is correct
23 Correct 754 ms 87880 KB Output is correct
24 Correct 661 ms 87880 KB Output is correct
25 Correct 615 ms 87880 KB Output is correct
26 Correct 649 ms 87880 KB Output is correct
27 Correct 632 ms 87880 KB Output is correct
28 Correct 808 ms 93944 KB Output is correct
29 Correct 836 ms 93944 KB Output is correct
30 Correct 898 ms 93972 KB Output is correct
31 Correct 889 ms 94080 KB Output is correct
32 Correct 754 ms 94080 KB Output is correct
33 Correct 838 ms 94080 KB Output is correct
34 Correct 388 ms 94080 KB Output is correct
35 Correct 909 ms 94080 KB Output is correct
36 Correct 793 ms 94080 KB Output is correct
37 Correct 897 ms 94080 KB Output is correct
38 Correct 797 ms 94080 KB Output is correct
39 Correct 878 ms 98968 KB Output is correct
40 Correct 1058 ms 98968 KB Output is correct
41 Correct 756 ms 98968 KB Output is correct
42 Correct 736 ms 98968 KB Output is correct
43 Correct 929 ms 98968 KB Output is correct
44 Correct 798 ms 98968 KB Output is correct
45 Correct 766 ms 99236 KB Output is correct
46 Correct 787 ms 99236 KB Output is correct
47 Correct 924 ms 99236 KB Output is correct
48 Correct 911 ms 99236 KB Output is correct
49 Correct 904 ms 99236 KB Output is correct
50 Correct 922 ms 99236 KB Output is correct
51 Correct 981 ms 99236 KB Output is correct
52 Correct 952 ms 99236 KB Output is correct