답안 #789753

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

int n;
vector<int> g1[200000], g2[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(const int &u)
{
    euler1[in1[u] = t1++] = u;
    for (const int &v : c1[u])
        dfs1(v);
    out1[u] = t1;
}
void dfs2(const int &u)
{
    in2[u] = t2++;
    for (const 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 idx)
{
    for (; idx < n; idx |= (idx + 1))
        t[idx]++;
}
int query(int idx)
{
    int res = 0;
    for (; idx >= 0; idx = (idx & (idx + 1)) - 1)
        res += t[idx];
    return res;
}

vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R)
{
    n = N;
    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++)
    {
        if (X[i] < Y[i]) swap(X[i], Y[i]);
        g1[X[i]].push_back(Y[i]);
        g2[Y[i]].push_back(X[i]);
    }

    iota(e, e + N, 0);
    for (int u = 0; u < N; u++)
        for (int v : g1[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 : g2[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];
        }
        events[in1[E[i]]-1].push_back({in2[S[i]], out2[S[i]]-1, -1, i});
        events[out1[E[i]]-1].push_back({in2[S[i]], out2[S[i]]-1, 1, i});
    }

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

    return A;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23764 KB Output is correct
2 Correct 12 ms 23792 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23776 KB Output is correct
5 Correct 16 ms 23772 KB Output is correct
6 Correct 11 ms 23764 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 11 ms 23792 KB Output is correct
9 Correct 12 ms 23880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23764 KB Output is correct
2 Correct 12 ms 23792 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23776 KB Output is correct
5 Correct 16 ms 23772 KB Output is correct
6 Correct 11 ms 23764 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 11 ms 23792 KB Output is correct
9 Correct 12 ms 23880 KB Output is correct
10 Correct 14 ms 24916 KB Output is correct
11 Correct 16 ms 24916 KB Output is correct
12 Correct 14 ms 24916 KB Output is correct
13 Correct 16 ms 25076 KB Output is correct
14 Correct 15 ms 25072 KB Output is correct
15 Correct 16 ms 25048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 449 ms 97052 KB Output is correct
2 Correct 489 ms 99340 KB Output is correct
3 Correct 435 ms 97548 KB Output is correct
4 Correct 379 ms 96664 KB Output is correct
5 Correct 416 ms 96588 KB Output is correct
6 Correct 396 ms 96600 KB Output is correct
7 Correct 403 ms 94812 KB Output is correct
8 Correct 443 ms 99268 KB Output is correct
9 Correct 406 ms 97756 KB Output is correct
10 Correct 321 ms 95308 KB Output is correct
11 Correct 331 ms 96424 KB Output is correct
12 Correct 354 ms 96324 KB Output is correct
13 Correct 544 ms 107148 KB Output is correct
14 Correct 565 ms 107072 KB Output is correct
15 Correct 544 ms 107048 KB Output is correct
16 Correct 526 ms 107144 KB Output is correct
17 Correct 425 ms 94948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23764 KB Output is correct
2 Correct 12 ms 23792 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23776 KB Output is correct
5 Correct 16 ms 23772 KB Output is correct
6 Correct 11 ms 23764 KB Output is correct
7 Correct 11 ms 23764 KB Output is correct
8 Correct 11 ms 23792 KB Output is correct
9 Correct 12 ms 23880 KB Output is correct
10 Correct 14 ms 24916 KB Output is correct
11 Correct 16 ms 24916 KB Output is correct
12 Correct 14 ms 24916 KB Output is correct
13 Correct 16 ms 25076 KB Output is correct
14 Correct 15 ms 25072 KB Output is correct
15 Correct 16 ms 25048 KB Output is correct
16 Correct 449 ms 97052 KB Output is correct
17 Correct 489 ms 99340 KB Output is correct
18 Correct 435 ms 97548 KB Output is correct
19 Correct 379 ms 96664 KB Output is correct
20 Correct 416 ms 96588 KB Output is correct
21 Correct 396 ms 96600 KB Output is correct
22 Correct 403 ms 94812 KB Output is correct
23 Correct 443 ms 99268 KB Output is correct
24 Correct 406 ms 97756 KB Output is correct
25 Correct 321 ms 95308 KB Output is correct
26 Correct 331 ms 96424 KB Output is correct
27 Correct 354 ms 96324 KB Output is correct
28 Correct 544 ms 107148 KB Output is correct
29 Correct 565 ms 107072 KB Output is correct
30 Correct 544 ms 107048 KB Output is correct
31 Correct 526 ms 107144 KB Output is correct
32 Correct 425 ms 94948 KB Output is correct
33 Correct 471 ms 96068 KB Output is correct
34 Correct 218 ms 49888 KB Output is correct
35 Correct 519 ms 97724 KB Output is correct
36 Correct 460 ms 97276 KB Output is correct
37 Correct 542 ms 97180 KB Output is correct
38 Correct 452 ms 97628 KB Output is correct
39 Correct 490 ms 104244 KB Output is correct
40 Correct 545 ms 102788 KB Output is correct
41 Correct 386 ms 95676 KB Output is correct
42 Correct 364 ms 96124 KB Output is correct
43 Correct 607 ms 102028 KB Output is correct
44 Correct 420 ms 96700 KB Output is correct
45 Correct 457 ms 104896 KB Output is correct
46 Correct 481 ms 104536 KB Output is correct
47 Correct 542 ms 107196 KB Output is correct
48 Correct 565 ms 107080 KB Output is correct
49 Correct 547 ms 107168 KB Output is correct
50 Correct 562 ms 107076 KB Output is correct
51 Correct 540 ms 101948 KB Output is correct
52 Correct 521 ms 101980 KB Output is correct