Submission #789750

# Submission time Handle Problem Language Result Execution time Memory
789750 2023-07-22T00:01:29 Z benjaminkleyn Werewolf (IOI18_werewolf) C++17
100 / 100
514 ms 93976 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]);
}

bool vis1[200000] = {false}, vis2[200000] = {false};
int euler1[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++;
    euler1[in1[u]] = u;
    for (int v : c1[u])
        dfs1(v);
    out1[u] = t1;
}
void dfs2(int u)
{
    vis2[u] = true;
    in2[u] = t2++;
    for (int v : c2[u])
        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);
    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]);
    }

    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 <= 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 (!vis1[i])
            dfs1(i);

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

    vector<Event> events;
    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.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 7 ms 14408 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14404 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 7 ms 14464 KB Output is correct
7 Correct 7 ms 14488 KB Output is correct
8 Correct 7 ms 14400 KB Output is correct
9 Correct 7 ms 14420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14408 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14404 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 7 ms 14464 KB Output is correct
7 Correct 7 ms 14488 KB Output is correct
8 Correct 7 ms 14400 KB Output is correct
9 Correct 7 ms 14420 KB Output is correct
10 Correct 10 ms 15700 KB Output is correct
11 Correct 11 ms 15660 KB Output is correct
12 Correct 11 ms 15700 KB Output is correct
13 Correct 11 ms 15828 KB Output is correct
14 Correct 11 ms 15820 KB Output is correct
15 Correct 11 ms 15820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 382 ms 86812 KB Output is correct
2 Correct 403 ms 89244 KB Output is correct
3 Correct 380 ms 87512 KB Output is correct
4 Correct 363 ms 86916 KB Output is correct
5 Correct 364 ms 86884 KB Output is correct
6 Correct 363 ms 86804 KB Output is correct
7 Correct 349 ms 86692 KB Output is correct
8 Correct 396 ms 89100 KB Output is correct
9 Correct 328 ms 87504 KB Output is correct
10 Correct 306 ms 86972 KB Output is correct
11 Correct 320 ms 86516 KB Output is correct
12 Correct 329 ms 86736 KB Output is correct
13 Correct 432 ms 93720 KB Output is correct
14 Correct 439 ms 93832 KB Output is correct
15 Correct 435 ms 93788 KB Output is correct
16 Correct 442 ms 93452 KB Output is correct
17 Correct 359 ms 86108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14408 KB Output is correct
2 Correct 7 ms 14420 KB Output is correct
3 Correct 7 ms 14404 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 8 ms 14420 KB Output is correct
6 Correct 7 ms 14464 KB Output is correct
7 Correct 7 ms 14488 KB Output is correct
8 Correct 7 ms 14400 KB Output is correct
9 Correct 7 ms 14420 KB Output is correct
10 Correct 10 ms 15700 KB Output is correct
11 Correct 11 ms 15660 KB Output is correct
12 Correct 11 ms 15700 KB Output is correct
13 Correct 11 ms 15828 KB Output is correct
14 Correct 11 ms 15820 KB Output is correct
15 Correct 11 ms 15820 KB Output is correct
16 Correct 382 ms 86812 KB Output is correct
17 Correct 403 ms 89244 KB Output is correct
18 Correct 380 ms 87512 KB Output is correct
19 Correct 363 ms 86916 KB Output is correct
20 Correct 364 ms 86884 KB Output is correct
21 Correct 363 ms 86804 KB Output is correct
22 Correct 349 ms 86692 KB Output is correct
23 Correct 396 ms 89100 KB Output is correct
24 Correct 328 ms 87504 KB Output is correct
25 Correct 306 ms 86972 KB Output is correct
26 Correct 320 ms 86516 KB Output is correct
27 Correct 329 ms 86736 KB Output is correct
28 Correct 432 ms 93720 KB Output is correct
29 Correct 439 ms 93832 KB Output is correct
30 Correct 435 ms 93788 KB Output is correct
31 Correct 442 ms 93452 KB Output is correct
32 Correct 359 ms 86108 KB Output is correct
33 Correct 399 ms 86668 KB Output is correct
34 Correct 222 ms 44860 KB Output is correct
35 Correct 437 ms 88096 KB Output is correct
36 Correct 395 ms 86576 KB Output is correct
37 Correct 514 ms 87520 KB Output is correct
38 Correct 399 ms 86956 KB Output is correct
39 Correct 427 ms 93732 KB Output is correct
40 Correct 494 ms 93108 KB Output is correct
41 Correct 381 ms 87112 KB Output is correct
42 Correct 321 ms 86596 KB Output is correct
43 Correct 467 ms 91540 KB Output is correct
44 Correct 387 ms 87528 KB Output is correct
45 Correct 385 ms 93976 KB Output is correct
46 Correct 391 ms 93728 KB Output is correct
47 Correct 438 ms 93460 KB Output is correct
48 Correct 434 ms 93332 KB Output is correct
49 Correct 435 ms 93492 KB Output is correct
50 Correct 508 ms 93356 KB Output is correct
51 Correct 475 ms 92980 KB Output is correct
52 Correct 480 ms 92988 KB Output is correct