#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]);
}
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(int u)
{
in1[u] = t1++;
euler1[in1[u]] = u;
for (int v : c1[u])
dfs1(v);
out1[u] = t1;
}
void dfs2(int u)
{
in2[u] = t2++;
for (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 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]);
}
iota(e, e + N, 0);
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;
}
iota(e, e + N, 0);
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 (!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(N, in2[euler1[idx]], 1);
for (auto &[l, r, t, i] : events[idx])
A[i] += t * query(l, r);
}
for (int &x : A)
x = (x > 0);
return A;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
19132 KB |
Output is correct |
2 |
Correct |
9 ms |
19156 KB |
Output is correct |
3 |
Correct |
10 ms |
19148 KB |
Output is correct |
4 |
Correct |
10 ms |
19156 KB |
Output is correct |
5 |
Correct |
10 ms |
19184 KB |
Output is correct |
6 |
Correct |
9 ms |
19148 KB |
Output is correct |
7 |
Correct |
10 ms |
19092 KB |
Output is correct |
8 |
Correct |
9 ms |
19156 KB |
Output is correct |
9 |
Correct |
10 ms |
19156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
19132 KB |
Output is correct |
2 |
Correct |
9 ms |
19156 KB |
Output is correct |
3 |
Correct |
10 ms |
19148 KB |
Output is correct |
4 |
Correct |
10 ms |
19156 KB |
Output is correct |
5 |
Correct |
10 ms |
19184 KB |
Output is correct |
6 |
Correct |
9 ms |
19148 KB |
Output is correct |
7 |
Correct |
10 ms |
19092 KB |
Output is correct |
8 |
Correct |
9 ms |
19156 KB |
Output is correct |
9 |
Correct |
10 ms |
19156 KB |
Output is correct |
10 |
Correct |
13 ms |
20180 KB |
Output is correct |
11 |
Correct |
12 ms |
20180 KB |
Output is correct |
12 |
Correct |
12 ms |
20228 KB |
Output is correct |
13 |
Correct |
12 ms |
20248 KB |
Output is correct |
14 |
Correct |
12 ms |
20244 KB |
Output is correct |
15 |
Correct |
13 ms |
20236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
395 ms |
90364 KB |
Output is correct |
2 |
Correct |
454 ms |
92488 KB |
Output is correct |
3 |
Correct |
390 ms |
90896 KB |
Output is correct |
4 |
Correct |
352 ms |
89820 KB |
Output is correct |
5 |
Correct |
360 ms |
89676 KB |
Output is correct |
6 |
Correct |
371 ms |
89732 KB |
Output is correct |
7 |
Correct |
387 ms |
88276 KB |
Output is correct |
8 |
Correct |
423 ms |
92416 KB |
Output is correct |
9 |
Correct |
346 ms |
90948 KB |
Output is correct |
10 |
Correct |
285 ms |
88416 KB |
Output is correct |
11 |
Correct |
311 ms |
89676 KB |
Output is correct |
12 |
Correct |
306 ms |
89444 KB |
Output is correct |
13 |
Correct |
499 ms |
96112 KB |
Output is correct |
14 |
Correct |
480 ms |
96104 KB |
Output is correct |
15 |
Correct |
490 ms |
96096 KB |
Output is correct |
16 |
Correct |
511 ms |
96168 KB |
Output is correct |
17 |
Correct |
357 ms |
88128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
19132 KB |
Output is correct |
2 |
Correct |
9 ms |
19156 KB |
Output is correct |
3 |
Correct |
10 ms |
19148 KB |
Output is correct |
4 |
Correct |
10 ms |
19156 KB |
Output is correct |
5 |
Correct |
10 ms |
19184 KB |
Output is correct |
6 |
Correct |
9 ms |
19148 KB |
Output is correct |
7 |
Correct |
10 ms |
19092 KB |
Output is correct |
8 |
Correct |
9 ms |
19156 KB |
Output is correct |
9 |
Correct |
10 ms |
19156 KB |
Output is correct |
10 |
Correct |
13 ms |
20180 KB |
Output is correct |
11 |
Correct |
12 ms |
20180 KB |
Output is correct |
12 |
Correct |
12 ms |
20228 KB |
Output is correct |
13 |
Correct |
12 ms |
20248 KB |
Output is correct |
14 |
Correct |
12 ms |
20244 KB |
Output is correct |
15 |
Correct |
13 ms |
20236 KB |
Output is correct |
16 |
Correct |
395 ms |
90364 KB |
Output is correct |
17 |
Correct |
454 ms |
92488 KB |
Output is correct |
18 |
Correct |
390 ms |
90896 KB |
Output is correct |
19 |
Correct |
352 ms |
89820 KB |
Output is correct |
20 |
Correct |
360 ms |
89676 KB |
Output is correct |
21 |
Correct |
371 ms |
89732 KB |
Output is correct |
22 |
Correct |
387 ms |
88276 KB |
Output is correct |
23 |
Correct |
423 ms |
92416 KB |
Output is correct |
24 |
Correct |
346 ms |
90948 KB |
Output is correct |
25 |
Correct |
285 ms |
88416 KB |
Output is correct |
26 |
Correct |
311 ms |
89676 KB |
Output is correct |
27 |
Correct |
306 ms |
89444 KB |
Output is correct |
28 |
Correct |
499 ms |
96112 KB |
Output is correct |
29 |
Correct |
480 ms |
96104 KB |
Output is correct |
30 |
Correct |
490 ms |
96096 KB |
Output is correct |
31 |
Correct |
511 ms |
96168 KB |
Output is correct |
32 |
Correct |
357 ms |
88128 KB |
Output is correct |
33 |
Correct |
445 ms |
90092 KB |
Output is correct |
34 |
Correct |
202 ms |
46484 KB |
Output is correct |
35 |
Correct |
509 ms |
91528 KB |
Output is correct |
36 |
Correct |
415 ms |
90444 KB |
Output is correct |
37 |
Correct |
477 ms |
90940 KB |
Output is correct |
38 |
Correct |
441 ms |
90756 KB |
Output is correct |
39 |
Correct |
465 ms |
96496 KB |
Output is correct |
40 |
Correct |
504 ms |
95232 KB |
Output is correct |
41 |
Correct |
378 ms |
89712 KB |
Output is correct |
42 |
Correct |
308 ms |
89392 KB |
Output is correct |
43 |
Correct |
493 ms |
94456 KB |
Output is correct |
44 |
Correct |
420 ms |
90568 KB |
Output is correct |
45 |
Correct |
414 ms |
96940 KB |
Output is correct |
46 |
Correct |
439 ms |
96756 KB |
Output is correct |
47 |
Correct |
494 ms |
96144 KB |
Output is correct |
48 |
Correct |
493 ms |
96096 KB |
Output is correct |
49 |
Correct |
495 ms |
96276 KB |
Output is correct |
50 |
Correct |
492 ms |
96132 KB |
Output is correct |
51 |
Correct |
473 ms |
94892 KB |
Output is correct |
52 |
Correct |
454 ms |
94968 KB |
Output is correct |