Submission #789745

# Submission time Handle Problem Language Result Execution time Memory
789745 2023-07-21T23:50:34 Z benjaminkleyn Werewolf (IOI18_werewolf) C++17
100 / 100
506 ms 106320 KB
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<int> g[200000];

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

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

struct Event
{
    int idx, l, r, t, i;
};
bool operator<(const Event &A, const Event &B)
{
    return make_pair(A.idx, A.t) < make_pair(B.idx, B.t);
}

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);

    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]);
    }

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

    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;
            }

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

    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 < 20; 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++)
    {
        c1[par1[i][0]].push_back(i);
        c2[par2[i][0]].push_back(i);
    }

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

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

    for (int i = 0; i < N; i++)
    {
        euler1[in1[i]] = i;
        euler2[in2[i]] = i;
    }

    vector<Event> events;
    for (int i = 0; i < Q; i++)
    {
        for (int k = 19; 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.push_back({in1[E[i]]-1, in2[S[i]], out2[S[i]]-1, 1, i});
        events.push_back({out1[E[i]]-1, in2[S[i]], out2[S[i]]-1, -1, i});
    }

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

    return A;
}

# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 8 ms 14408 KB Output is correct
3 Correct 9 ms 14368 KB Output is correct
4 Correct 7 ms 14404 KB Output is correct
5 Correct 9 ms 14416 KB Output is correct
6 Correct 7 ms 14444 KB Output is correct
7 Correct 7 ms 14396 KB Output is correct
8 Correct 7 ms 14484 KB Output is correct
9 Correct 7 ms 14408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 8 ms 14408 KB Output is correct
3 Correct 9 ms 14368 KB Output is correct
4 Correct 7 ms 14404 KB Output is correct
5 Correct 9 ms 14416 KB Output is correct
6 Correct 7 ms 14444 KB Output is correct
7 Correct 7 ms 14396 KB Output is correct
8 Correct 7 ms 14484 KB Output is correct
9 Correct 7 ms 14408 KB Output is correct
10 Correct 12 ms 15788 KB Output is correct
11 Correct 12 ms 15700 KB Output is correct
12 Correct 14 ms 15728 KB Output is correct
13 Correct 12 ms 15928 KB Output is correct
14 Correct 12 ms 15868 KB Output is correct
15 Correct 12 ms 15828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 440 ms 86944 KB Output is correct
2 Correct 453 ms 90500 KB Output is correct
3 Correct 398 ms 88116 KB Output is correct
4 Correct 391 ms 87180 KB Output is correct
5 Correct 402 ms 87184 KB Output is correct
6 Correct 399 ms 86976 KB Output is correct
7 Correct 393 ms 86964 KB Output is correct
8 Correct 421 ms 90632 KB Output is correct
9 Correct 358 ms 88148 KB Output is correct
10 Correct 351 ms 87188 KB Output is correct
11 Correct 348 ms 89296 KB Output is correct
12 Correct 351 ms 92184 KB Output is correct
13 Correct 505 ms 102324 KB Output is correct
14 Correct 486 ms 98164 KB Output is correct
15 Correct 481 ms 102200 KB Output is correct
16 Correct 484 ms 104176 KB Output is correct
17 Correct 393 ms 95200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14420 KB Output is correct
2 Correct 8 ms 14408 KB Output is correct
3 Correct 9 ms 14368 KB Output is correct
4 Correct 7 ms 14404 KB Output is correct
5 Correct 9 ms 14416 KB Output is correct
6 Correct 7 ms 14444 KB Output is correct
7 Correct 7 ms 14396 KB Output is correct
8 Correct 7 ms 14484 KB Output is correct
9 Correct 7 ms 14408 KB Output is correct
10 Correct 12 ms 15788 KB Output is correct
11 Correct 12 ms 15700 KB Output is correct
12 Correct 14 ms 15728 KB Output is correct
13 Correct 12 ms 15928 KB Output is correct
14 Correct 12 ms 15868 KB Output is correct
15 Correct 12 ms 15828 KB Output is correct
16 Correct 440 ms 86944 KB Output is correct
17 Correct 453 ms 90500 KB Output is correct
18 Correct 398 ms 88116 KB Output is correct
19 Correct 391 ms 87180 KB Output is correct
20 Correct 402 ms 87184 KB Output is correct
21 Correct 399 ms 86976 KB Output is correct
22 Correct 393 ms 86964 KB Output is correct
23 Correct 421 ms 90632 KB Output is correct
24 Correct 358 ms 88148 KB Output is correct
25 Correct 351 ms 87188 KB Output is correct
26 Correct 348 ms 89296 KB Output is correct
27 Correct 351 ms 92184 KB Output is correct
28 Correct 505 ms 102324 KB Output is correct
29 Correct 486 ms 98164 KB Output is correct
30 Correct 481 ms 102200 KB Output is correct
31 Correct 484 ms 104176 KB Output is correct
32 Correct 393 ms 95200 KB Output is correct
33 Correct 444 ms 90212 KB Output is correct
34 Correct 225 ms 56356 KB Output is correct
35 Correct 473 ms 98332 KB Output is correct
36 Correct 411 ms 95888 KB Output is correct
37 Correct 475 ms 97556 KB Output is correct
38 Correct 408 ms 96440 KB Output is correct
39 Correct 445 ms 105912 KB Output is correct
40 Correct 506 ms 106060 KB Output is correct
41 Correct 411 ms 96868 KB Output is correct
42 Correct 327 ms 95928 KB Output is correct
43 Correct 467 ms 103556 KB Output is correct
44 Correct 422 ms 97572 KB Output is correct
45 Correct 402 ms 106320 KB Output is correct
46 Correct 415 ms 106004 KB Output is correct
47 Correct 455 ms 104112 KB Output is correct
48 Correct 442 ms 104056 KB Output is correct
49 Correct 461 ms 104220 KB Output is correct
50 Correct 459 ms 103988 KB Output is correct
51 Correct 481 ms 105912 KB Output is correct
52 Correct 482 ms 106028 KB Output is correct