답안 #789742

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
789742 2023-07-21T23:48:02 Z benjaminkleyn 늑대인간 (IOI18_werewolf) C++17
0 / 100
400 ms 90192 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 = 0;
    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;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 6 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Incorrect 6 ms 14356 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 6 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Incorrect 6 ms 14356 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 371 ms 86748 KB Output is correct
2 Correct 400 ms 90192 KB Output is correct
3 Correct 373 ms 87840 KB Output is correct
4 Correct 361 ms 86956 KB Output is correct
5 Correct 370 ms 86940 KB Output is correct
6 Correct 362 ms 86836 KB Output is correct
7 Correct 365 ms 86808 KB Output is correct
8 Correct 397 ms 90160 KB Output is correct
9 Correct 339 ms 87836 KB Output is correct
10 Incorrect 311 ms 86932 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 6 ms 14420 KB Output is correct
3 Correct 7 ms 14420 KB Output is correct
4 Incorrect 6 ms 14356 KB Output isn't correct
5 Halted 0 ms 0 KB -