답안 #530828

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
530828 2022-02-26T22:05:12 Z jerzyk 늑대인간 (IOI18_werewolf) C++14
100 / 100
919 ms 96792 KB
#include <bits/stdc++.h>

using namespace std;
const int N = 2 * 100 * 1000 + 7;
int faul[N], faur[N], jp[21][N], p[N], k[N];
vector<int> ed[N], aed[N], q[N], ans;
set<int> sp[N];
set<int>::iterator it;

int FindL(int v)
{
    if(faul[v] == v) return v;
    faul[v] = FindL(faul[v]); return faul[v];
}

void Unionl(int a, int b)
{
    if(FindL(a) == FindL(b)) return;
    a = FindL(a); b = FindL(b);
    ed[a].push_back(b); ed[b].push_back(a);
    faul[b] = a;
}

void DFS(int v, int &pr)
{
    ++pr;
    p[v] = pr;
    //cout << v << "\n";
    for(int i = 0; i < (int)ed[v].size(); ++i)
    {
        if(p[ed[v][i]] == 0)
        {
            jp[0][ed[v][i]] = v;
            DFS(ed[v][i], pr);
        }
    }
    k[v] = pr;
}

int Jump(int v, int x)
{
    for(int i = 19; i >= 0; --i)
        if(jp[i][v] >= x) v = jp[i][v];
    return v;
}

int FindR(int v)
{
    if(faur[v] == v) return v;
    faur[v] = FindR(faur[v]); return faur[v];
}

void DoJMP(int n)
{
    for(int j = 1; j <= 19; ++j)
        for(int i = 0; i < n; ++i)
            jp[j][i] = jp[j - 1][jp[j - 1][i]];
}

void UnionR(int a, int b)
{
    if(FindR(a) == FindR(b)) return;
    a = FindR(a); b = FindR(b);
    if(sp[a].size() < sp[b].size()) swap(a, b);
    faur[b] = a;
    while(sp[b].size() > 0)
    {
        sp[a].insert(*sp[b].begin()); sp[b].erase(sp[b].begin());
    }
}

vector<int> check_validity(int n, vector<int>X, vector<int>Y, vector<int>S, vector<int>E, vector<int>L, vector<int>R)
{
    int m = X.size(), x = 0, y;
    vector<pair<int, int>> e;
    for(int i = 0; i < (int)S.size(); ++i)
    {
        q[R[i]].push_back(i);
        ans.push_back(1);
    }
    for(int i = 0; i < n; ++i) faul[i] = i;
    for(int i = 0; i < n; ++i) faur[i] = i;
    for(int i = 0; i < m; ++i)
    {
        if(X[i] > Y[i]) swap(X[i], Y[i]);
        aed[Y[i]].push_back(X[i]);
        e.push_back(make_pair(X[i], Y[i]));
    }
    sort(e.begin(), e.end());
    for(int i = m - 1; i >= 0; --i) Unionl(e[i].first, e[i].second);
    DFS(0, x);
    DoJMP(n);
    for(int i = 0; i < n; ++i) sp[i].insert(p[i]);
    for(int i = 0; i < n; ++i)
    {
        //cout << "i: " << i << " " << p[i] << "\n";
        for(int j = 0; j < (int)aed[i].size(); ++j)
            if(aed[i][j] < i)
                UnionR(i, aed[i][j]);
        for(int j = 0; j < (int)q[i].size(); ++j)
        {
            x = FindR(E[q[i][j]]);
            y = Jump(S[q[i][j]], L[q[i][j]]);
            //if(q[i][j] == 1)
                //cout << i << " " << q[i][j] << " " << x << " " << y << "\n";
            it = sp[x].lower_bound(p[y]);
            if(it == sp[x].end() || (*it) > k[y])
                ans[q[i][j]] = 0;
        }
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23884 KB Output is correct
2 Correct 14 ms 23876 KB Output is correct
3 Correct 12 ms 23916 KB Output is correct
4 Correct 12 ms 23884 KB Output is correct
5 Correct 11 ms 23920 KB Output is correct
6 Correct 12 ms 23896 KB Output is correct
7 Correct 12 ms 23916 KB Output is correct
8 Correct 12 ms 23916 KB Output is correct
9 Correct 11 ms 23884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23884 KB Output is correct
2 Correct 14 ms 23876 KB Output is correct
3 Correct 12 ms 23916 KB Output is correct
4 Correct 12 ms 23884 KB Output is correct
5 Correct 11 ms 23920 KB Output is correct
6 Correct 12 ms 23896 KB Output is correct
7 Correct 12 ms 23916 KB Output is correct
8 Correct 12 ms 23916 KB Output is correct
9 Correct 11 ms 23884 KB Output is correct
10 Correct 16 ms 24908 KB Output is correct
11 Correct 16 ms 24800 KB Output is correct
12 Correct 16 ms 24744 KB Output is correct
13 Correct 16 ms 24824 KB Output is correct
14 Correct 18 ms 24792 KB Output is correct
15 Correct 17 ms 24944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 906 ms 80564 KB Output is correct
2 Correct 680 ms 87752 KB Output is correct
3 Correct 638 ms 86584 KB Output is correct
4 Correct 748 ms 86656 KB Output is correct
5 Correct 770 ms 86580 KB Output is correct
6 Correct 843 ms 86468 KB Output is correct
7 Correct 800 ms 85616 KB Output is correct
8 Correct 527 ms 87740 KB Output is correct
9 Correct 373 ms 87356 KB Output is correct
10 Correct 356 ms 84448 KB Output is correct
11 Correct 388 ms 84540 KB Output is correct
12 Correct 485 ms 86992 KB Output is correct
13 Correct 680 ms 94772 KB Output is correct
14 Correct 668 ms 94896 KB Output is correct
15 Correct 679 ms 94988 KB Output is correct
16 Correct 679 ms 94904 KB Output is correct
17 Correct 805 ms 85340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23884 KB Output is correct
2 Correct 14 ms 23876 KB Output is correct
3 Correct 12 ms 23916 KB Output is correct
4 Correct 12 ms 23884 KB Output is correct
5 Correct 11 ms 23920 KB Output is correct
6 Correct 12 ms 23896 KB Output is correct
7 Correct 12 ms 23916 KB Output is correct
8 Correct 12 ms 23916 KB Output is correct
9 Correct 11 ms 23884 KB Output is correct
10 Correct 16 ms 24908 KB Output is correct
11 Correct 16 ms 24800 KB Output is correct
12 Correct 16 ms 24744 KB Output is correct
13 Correct 16 ms 24824 KB Output is correct
14 Correct 18 ms 24792 KB Output is correct
15 Correct 17 ms 24944 KB Output is correct
16 Correct 906 ms 80564 KB Output is correct
17 Correct 680 ms 87752 KB Output is correct
18 Correct 638 ms 86584 KB Output is correct
19 Correct 748 ms 86656 KB Output is correct
20 Correct 770 ms 86580 KB Output is correct
21 Correct 843 ms 86468 KB Output is correct
22 Correct 800 ms 85616 KB Output is correct
23 Correct 527 ms 87740 KB Output is correct
24 Correct 373 ms 87356 KB Output is correct
25 Correct 356 ms 84448 KB Output is correct
26 Correct 388 ms 84540 KB Output is correct
27 Correct 485 ms 86992 KB Output is correct
28 Correct 680 ms 94772 KB Output is correct
29 Correct 668 ms 94896 KB Output is correct
30 Correct 679 ms 94988 KB Output is correct
31 Correct 679 ms 94904 KB Output is correct
32 Correct 805 ms 85340 KB Output is correct
33 Correct 882 ms 87312 KB Output is correct
34 Correct 296 ms 56748 KB Output is correct
35 Correct 876 ms 90884 KB Output is correct
36 Correct 835 ms 87264 KB Output is correct
37 Correct 838 ms 89768 KB Output is correct
38 Correct 849 ms 88144 KB Output is correct
39 Correct 919 ms 88892 KB Output is correct
40 Correct 702 ms 96792 KB Output is correct
41 Correct 620 ms 89180 KB Output is correct
42 Correct 508 ms 88156 KB Output is correct
43 Correct 751 ms 96680 KB Output is correct
44 Correct 680 ms 89836 KB Output is correct
45 Correct 485 ms 90596 KB Output is correct
46 Correct 489 ms 89652 KB Output is correct
47 Correct 658 ms 94988 KB Output is correct
48 Correct 682 ms 94944 KB Output is correct
49 Correct 696 ms 95068 KB Output is correct
50 Correct 692 ms 94912 KB Output is correct
51 Correct 620 ms 96068 KB Output is correct
52 Correct 624 ms 96008 KB Output is correct