답안 #789751

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
789751 2023-07-22T00:10:57 Z benjaminkleyn 늑대인간 (IOI18_werewolf) C++17
100 / 100
482 ms 97092 KB
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<int> g[200000];

int par1[200000][20], par2[200000][20];
int e[200000];
int find(int u)
{
    return e[u] == u ? u : e[u] = find(e[u]);
}

int euler1[200000];
int in1[200000] = {0}, out1[200000] = {0}, t1 = 0;
int in2[200000] = {0}, out2[200000] = {0}, t2 = 0;
vector<int> c1[200000], c2[200000];
void dfs1(int u)
{
    in1[u] = t1++;
    euler1[in1[u]] = u;
    for (int v : c1[u])
        dfs1(v);
    out1[u] = t1;
}
void dfs2(int u)
{
    in2[u] = t2++;
    for (int v : c2[u])
        dfs2(v);
    out2[u] = t2;
}

struct Event
{
    int l, r, t, i;
};
vector<Event> events[200000];

int t[200000] = {0};
void update(int N, int idx, int val)
{
    for (; idx < N; idx |= (idx + 1))
        t[idx] += val;
}
int quer(int r)
{
    int res = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1)
        res += t[r];
    return res;
}
int query(int l, int r)
{
    return quer(r) - quer(l - 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)
{
    int Q = S.size(), M = X.size();
    vector<int> A(Q, 0);
    int K = 0;
    while ((1 << K) < N) K++;

    for (int i = 0; i < N; i++)
        par1[i][0] = par2[i][0] = i;

    for (int i = 0; i < M; i++)
    {
        g[X[i]].push_back(Y[i]);
        g[Y[i]].push_back(X[i]);
    }

    iota(e, e + N, 0);

    for (int u = 0; u < N; u++)
        for (int v : g[u])
            if (v < u)
            {
                v = find(v);
                e[v] = u;
                par1[v][0] = u;
            }

    iota(e, e + N, 0);

    for (int u = N - 1; u >= 0; u--)
        for (int v : g[u])
            if (v > u)
            {
                v = find(v);
                e[v] = u;
                par2[v][0] = u;
            }

    for (int k = 1; k <= K; k++)
        for (int u = 0; u < N; u++)
        {
            par1[u][k] = par1[par1[u][k-1]][k-1];
            par2[u][k] = par2[par2[u][k-1]][k-1];
        }

    for (int i = 0; i < N; i++)
    {
        if (par1[i][0] != i)
            c1[par1[i][0]].push_back(i);
        if (par2[i][0] != i)
            c2[par2[i][0]].push_back(i);
    }

    for (int i = N - 1; i >= 0; i--)
        if (!in1[i])
            dfs1(i);

    for (int i = 0; i < N; i++)
        if (!in2[i])
            dfs2(i);

    for (int i = 0; i < Q; i++)
    {
        for (int k = K; k >= 0; k--)
        {
            if (par1[E[i]][k] <= R[i])
                E[i] = par1[E[i]][k];
            if (par2[S[i]][k] >= L[i])
                S[i] = par2[S[i]][k];
        }
    }
    for (int i = 0; i < Q; i++)
        events[out1[E[i]]-1].push_back({in2[S[i]], out2[S[i]]-1, 1, i});
    for (int i = 0; i < Q; i++)
        events[in1[E[i]]-1].push_back({in2[S[i]], out2[S[i]]-1, -1, i});

    for (int idx = 0; idx < N; idx++)
    {
        update(N, in2[euler1[idx]], 1);
        for (auto &[l, r, t, i] : events[idx])
            A[i] += t * query(l, r);
    }
    for (int &x : A)
        x = (x > 0);

    return A;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19156 KB Output is correct
2 Correct 9 ms 19156 KB Output is correct
3 Correct 10 ms 19060 KB Output is correct
4 Correct 10 ms 19156 KB Output is correct
5 Correct 9 ms 19184 KB Output is correct
6 Correct 9 ms 19188 KB Output is correct
7 Correct 9 ms 19156 KB Output is correct
8 Correct 9 ms 19156 KB Output is correct
9 Correct 9 ms 19140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19156 KB Output is correct
2 Correct 9 ms 19156 KB Output is correct
3 Correct 10 ms 19060 KB Output is correct
4 Correct 10 ms 19156 KB Output is correct
5 Correct 9 ms 19184 KB Output is correct
6 Correct 9 ms 19188 KB Output is correct
7 Correct 9 ms 19156 KB Output is correct
8 Correct 9 ms 19156 KB Output is correct
9 Correct 9 ms 19140 KB Output is correct
10 Correct 12 ms 20200 KB Output is correct
11 Correct 12 ms 20180 KB Output is correct
12 Correct 12 ms 20180 KB Output is correct
13 Correct 12 ms 20328 KB Output is correct
14 Correct 11 ms 20308 KB Output is correct
15 Correct 13 ms 20264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 356 ms 90244 KB Output is correct
2 Correct 375 ms 92364 KB Output is correct
3 Correct 352 ms 90780 KB Output is correct
4 Correct 331 ms 89880 KB Output is correct
5 Correct 341 ms 89832 KB Output is correct
6 Correct 339 ms 89804 KB Output is correct
7 Correct 343 ms 88188 KB Output is correct
8 Correct 350 ms 92432 KB Output is correct
9 Correct 322 ms 90908 KB Output is correct
10 Correct 277 ms 88572 KB Output is correct
11 Correct 295 ms 89544 KB Output is correct
12 Correct 291 ms 89472 KB Output is correct
13 Correct 402 ms 96088 KB Output is correct
14 Correct 415 ms 96188 KB Output is correct
15 Correct 420 ms 96216 KB Output is correct
16 Correct 396 ms 96092 KB Output is correct
17 Correct 361 ms 88916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 19156 KB Output is correct
2 Correct 9 ms 19156 KB Output is correct
3 Correct 10 ms 19060 KB Output is correct
4 Correct 10 ms 19156 KB Output is correct
5 Correct 9 ms 19184 KB Output is correct
6 Correct 9 ms 19188 KB Output is correct
7 Correct 9 ms 19156 KB Output is correct
8 Correct 9 ms 19156 KB Output is correct
9 Correct 9 ms 19140 KB Output is correct
10 Correct 12 ms 20200 KB Output is correct
11 Correct 12 ms 20180 KB Output is correct
12 Correct 12 ms 20180 KB Output is correct
13 Correct 12 ms 20328 KB Output is correct
14 Correct 11 ms 20308 KB Output is correct
15 Correct 13 ms 20264 KB Output is correct
16 Correct 356 ms 90244 KB Output is correct
17 Correct 375 ms 92364 KB Output is correct
18 Correct 352 ms 90780 KB Output is correct
19 Correct 331 ms 89880 KB Output is correct
20 Correct 341 ms 89832 KB Output is correct
21 Correct 339 ms 89804 KB Output is correct
22 Correct 343 ms 88188 KB Output is correct
23 Correct 350 ms 92432 KB Output is correct
24 Correct 322 ms 90908 KB Output is correct
25 Correct 277 ms 88572 KB Output is correct
26 Correct 295 ms 89544 KB Output is correct
27 Correct 291 ms 89472 KB Output is correct
28 Correct 402 ms 96088 KB Output is correct
29 Correct 415 ms 96188 KB Output is correct
30 Correct 420 ms 96216 KB Output is correct
31 Correct 396 ms 96092 KB Output is correct
32 Correct 361 ms 88916 KB Output is correct
33 Correct 392 ms 90096 KB Output is correct
34 Correct 206 ms 46532 KB Output is correct
35 Correct 403 ms 91528 KB Output is correct
36 Correct 371 ms 90540 KB Output is correct
37 Correct 391 ms 90940 KB Output is correct
38 Correct 403 ms 90744 KB Output is correct
39 Correct 396 ms 96532 KB Output is correct
40 Correct 482 ms 95324 KB Output is correct
41 Correct 348 ms 89532 KB Output is correct
42 Correct 303 ms 89400 KB Output is correct
43 Correct 445 ms 94596 KB Output is correct
44 Correct 363 ms 90524 KB Output is correct
45 Correct 389 ms 97092 KB Output is correct
46 Correct 376 ms 96760 KB Output is correct
47 Correct 428 ms 96180 KB Output is correct
48 Correct 412 ms 96188 KB Output is correct
49 Correct 420 ms 96220 KB Output is correct
50 Correct 413 ms 96092 KB Output is correct
51 Correct 447 ms 94812 KB Output is correct
52 Correct 453 ms 94884 KB Output is correct