#include "werewolf.h"
#include <bits/stdc++.h>
std::vector<int> check_validity(int n, std::vector<int> x, std::vector<int> y, std::vector<int> s, std::vector<int> e, std::vector<int> a, std::vector<int> b) {
int q = s.size(), m = x.size();
std::vector<int> pr(n);
std::function<int(int)> find = [&](int u) {
return u == pr[u] ? u : pr[u] = find(pr[u]);
};
std::vector<std::vector<int>> g(n), tr(n);
for (int i = 0; i < m; ++i) {
g[x[i]].push_back(y[i]);
g[y[i]].push_back(x[i]);
}
std::vector<int> ind(n), rank(n);
std::vector<std::vector<std::array<int, 2>>> at(n);
auto solve = [&](std::vector<int> &tin, std::vector<int> &tout, std::vector<int> &head) {
iota(pr.begin(), pr.end(), 0);
for (int i = 0; i < n; ++i) {
int u = ind[i];
for (int j : g[u]) {
if (rank[j] < i && (j = find(j)) != u) {
pr[j] = u;
tr[u].push_back(j);
}
}
for (auto [j, v] : at[u]) {
head[j] = find(v);
}
}
int timer = 0;
std::function<void(int)> dfs = [&](int u) {
tin[u] = ++timer;
for (int v : tr[u]) {
dfs(v);
}
tout[u] = timer;
};
dfs(ind.back());
};
std::vector tin(2, std::vector<int>(n)), tout(2, std::vector<int>(n)), head(2, std::vector<int>(q));
for (int i = 0; i < n; ++i) {
ind[i] = n - 1 - i;
rank[n - 1 - i] = i;
}
for (int i = 0; i < q; ++i) {
at[a[i]].push_back({i, s[i]});
}
solve(tin[0], tout[0], head[0]);
for (int i = 0; i < n; ++i) {
ind[i] = i;
rank[i] = i;
std::vector<int>().swap(tr[i]);
std::vector<std::array<int, 2>>().swap(at[i]);
}
for (int i = 0; i < q; ++i) {
at[b[i]].push_back({i, e[i]});
}
solve(tin[1], tout[1], head[1]);
std::vector<std::vector<std::array<int, 3>>> queries(n + 1);
std::vector<int> ft(n + 1);
for (int i = 0; i < q; ++i) {
std::array<std::array<int, 2>, 2> range;
for (int j = 0; j < 2; ++j) {
range[j] = {tin[j][head[j][i]], tout[j][head[j][i]]};
}
queries[range[0][0] - 1].push_back({range[1][0], range[1][1], -i - 1});
queries[range[0][1]].push_back({range[1][0], range[1][1], i + 1});
}
auto upd = [&](int i) {
for (; i <= n; i += i & -i) {
++ft[i];
}
};
auto qry = [&](int i) {
int cnt = 0;
for (; i; i -= i & -i) {
cnt += ft[i];
}
return cnt;
};
std::vector<int> res(q), pos(n + 1);
for (int i = 0; i < n; ++i) {
pos[tin[0][i]] = i;
}
for (int i = 1; i <= n; ++i) {
upd(tin[1][pos[i]]);
for (auto [l, r, id] : queries[i]) {
if (id > 0) {
res[id - 1] += qry(r) - qry(l - 1);
} else {
res[-1 - id] -= qry(r) - qry(l - 1);
}
}
}
for (int i = 0; i < q; ++i) {
res[i] = res[i] > 0;
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
360 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
360 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
5 ms |
1372 KB |
Output is correct |
11 |
Correct |
4 ms |
1372 KB |
Output is correct |
12 |
Correct |
4 ms |
1372 KB |
Output is correct |
13 |
Correct |
6 ms |
1628 KB |
Output is correct |
14 |
Correct |
4 ms |
1452 KB |
Output is correct |
15 |
Correct |
4 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
340 ms |
59660 KB |
Output is correct |
2 |
Correct |
308 ms |
63808 KB |
Output is correct |
3 |
Correct |
290 ms |
60228 KB |
Output is correct |
4 |
Correct |
319 ms |
58436 KB |
Output is correct |
5 |
Correct |
295 ms |
58888 KB |
Output is correct |
6 |
Correct |
348 ms |
59712 KB |
Output is correct |
7 |
Correct |
278 ms |
57668 KB |
Output is correct |
8 |
Correct |
312 ms |
63552 KB |
Output is correct |
9 |
Correct |
251 ms |
59968 KB |
Output is correct |
10 |
Correct |
257 ms |
56824 KB |
Output is correct |
11 |
Correct |
272 ms |
56848 KB |
Output is correct |
12 |
Correct |
304 ms |
58876 KB |
Output is correct |
13 |
Correct |
313 ms |
67136 KB |
Output is correct |
14 |
Correct |
314 ms |
67140 KB |
Output is correct |
15 |
Correct |
323 ms |
67412 KB |
Output is correct |
16 |
Correct |
334 ms |
67084 KB |
Output is correct |
17 |
Correct |
294 ms |
57616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
360 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
5 ms |
1372 KB |
Output is correct |
11 |
Correct |
4 ms |
1372 KB |
Output is correct |
12 |
Correct |
4 ms |
1372 KB |
Output is correct |
13 |
Correct |
6 ms |
1628 KB |
Output is correct |
14 |
Correct |
4 ms |
1452 KB |
Output is correct |
15 |
Correct |
4 ms |
1372 KB |
Output is correct |
16 |
Correct |
340 ms |
59660 KB |
Output is correct |
17 |
Correct |
308 ms |
63808 KB |
Output is correct |
18 |
Correct |
290 ms |
60228 KB |
Output is correct |
19 |
Correct |
319 ms |
58436 KB |
Output is correct |
20 |
Correct |
295 ms |
58888 KB |
Output is correct |
21 |
Correct |
348 ms |
59712 KB |
Output is correct |
22 |
Correct |
278 ms |
57668 KB |
Output is correct |
23 |
Correct |
312 ms |
63552 KB |
Output is correct |
24 |
Correct |
251 ms |
59968 KB |
Output is correct |
25 |
Correct |
257 ms |
56824 KB |
Output is correct |
26 |
Correct |
272 ms |
56848 KB |
Output is correct |
27 |
Correct |
304 ms |
58876 KB |
Output is correct |
28 |
Correct |
313 ms |
67136 KB |
Output is correct |
29 |
Correct |
314 ms |
67140 KB |
Output is correct |
30 |
Correct |
323 ms |
67412 KB |
Output is correct |
31 |
Correct |
334 ms |
67084 KB |
Output is correct |
32 |
Correct |
294 ms |
57616 KB |
Output is correct |
33 |
Correct |
370 ms |
69112 KB |
Output is correct |
34 |
Correct |
187 ms |
41088 KB |
Output is correct |
35 |
Correct |
446 ms |
72416 KB |
Output is correct |
36 |
Correct |
346 ms |
68928 KB |
Output is correct |
37 |
Correct |
385 ms |
71372 KB |
Output is correct |
38 |
Correct |
410 ms |
69692 KB |
Output is correct |
39 |
Correct |
424 ms |
83056 KB |
Output is correct |
40 |
Correct |
468 ms |
77208 KB |
Output is correct |
41 |
Correct |
354 ms |
69624 KB |
Output is correct |
42 |
Correct |
301 ms |
67484 KB |
Output is correct |
43 |
Correct |
472 ms |
77320 KB |
Output is correct |
44 |
Correct |
374 ms |
70976 KB |
Output is correct |
45 |
Correct |
316 ms |
83004 KB |
Output is correct |
46 |
Correct |
306 ms |
82496 KB |
Output is correct |
47 |
Correct |
357 ms |
75588 KB |
Output is correct |
48 |
Correct |
359 ms |
75584 KB |
Output is correct |
49 |
Correct |
328 ms |
75584 KB |
Output is correct |
50 |
Correct |
362 ms |
75504 KB |
Output is correct |
51 |
Correct |
363 ms |
75928 KB |
Output is correct |
52 |
Correct |
410 ms |
75844 KB |
Output is correct |