#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 |
7 ms |
14384 KB |
Output is correct |
3 |
Correct |
7 ms |
14404 KB |
Output is correct |
4 |
Incorrect |
7 ms |
14420 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14384 KB |
Output is correct |
3 |
Correct |
7 ms |
14404 KB |
Output is correct |
4 |
Incorrect |
7 ms |
14420 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
386 ms |
86792 KB |
Output is correct |
2 |
Correct |
414 ms |
90184 KB |
Output is correct |
3 |
Correct |
389 ms |
87856 KB |
Output is correct |
4 |
Correct |
376 ms |
86920 KB |
Output is correct |
5 |
Correct |
368 ms |
86832 KB |
Output is correct |
6 |
Correct |
371 ms |
86836 KB |
Output is correct |
7 |
Correct |
359 ms |
86688 KB |
Output is correct |
8 |
Correct |
378 ms |
90252 KB |
Output is correct |
9 |
Correct |
333 ms |
87828 KB |
Output is correct |
10 |
Incorrect |
316 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 |
7 ms |
14384 KB |
Output is correct |
3 |
Correct |
7 ms |
14404 KB |
Output is correct |
4 |
Incorrect |
7 ms |
14420 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |