#include "werewolf.h"
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
using namespace std;
vector<int> dsu_tree[2][200000], graph[200000];
int N, p[2][20][200000], cnt, cmp[2][200000], order[2][200000];
pair<int, int> bounds[2][200000];
void dfs(int node, int t) {
bounds[t][node] = {cnt, cnt};
order[t][cnt] = node;
cnt++;
FOR(i, 1, 20) {
if (p[t][i - 1][node] == -1) break;
p[t][i][node] = p[t][i - 1][p[t][i - 1][node]];
}
for (int i : dsu_tree[t][node]) {
p[t][0][i] = node;
dfs(i, t);
bounds[t][node].second =
max(bounds[t][node].second, bounds[t][i].second);
}
}
int find(int a, int t) {
while (a != cmp[t][a]) cmp[t][a] = cmp[t][cmp[t][a]], a = cmp[t][a];
return a;
}
void onion(int a, int b, int t) {
cmp[t][find(a, t)] = cmp[t][find(b, t)];
}
vector<int> seg[800000];
void build(int node = 1, int l = 0, int r = N - 1) {
if (l == r) seg[node] = {bounds[0][order[1][l]].first};
else {
int mid = (l + r) / 2;
build(node * 2, l, mid);
build(node * 2 + 1, mid + 1, r);
int lptr = 0, rptr = 0;
int lsz = seg[node * 2].size(), rsz = seg[node * 2 + 1].size();
while (lptr < lsz && rptr < rsz) {
if (seg[node * 2][lptr] < seg[node * 2 + 1][rptr]) {
seg[node].push_back(seg[node * 2][lptr++]);
} else {
seg[node].push_back(seg[node * 2 + 1][rptr++]);
}
}
while (lptr < lsz) seg[node].push_back(seg[node * 2][lptr++]);
while (rptr < rsz) seg[node].push_back(seg[node * 2 + 1][rptr++]);
}
}
bool query(int a, int b, int x, int y, int node = 1, int l = 0, int r = N - 1) {
if (r < a || l > b) return 0;
if (r <= b && l >= a) return (upper_bound(seg[node].begin(), seg[node].end(), y) - lower_bound(seg[node].begin(), seg[node].end(), x) != 0);
int mid = (l + r) / 2;
return (query(a, b, x, y, node * 2, l, mid) || query(a, b, x, y, node * 2 + 1, mid + 1, r));
}
vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) {
::N = N;
int Q = S.size();
vector<int> A(Q);
FOR(i, 0, N) cmp[0][i] = cmp[1][i] = i;
FOR(i, 0, X.size()) {
graph[X[i]].push_back(Y[i]);
graph[Y[i]].push_back(X[i]);
}
for (int i = N - 1; ~i; i--)
for (int j : graph[i])
if (j > i && find(j, 0) != find(i, 0)) {
dsu_tree[0][i].push_back(find(j, 0));
onion(j, i, 0);
}
for (int i = 0; i < N; i++)
for (int j : graph[i])
if (j < i && find(j, 1) != find(i, 1)) {
dsu_tree[1][i].push_back(find(j, 1));
onion(j, i, 1);
}
memset(p, -1, sizeof(p));
cnt = 0;
dfs(0, 0);
cnt = 0;
dfs(N - 1, 1);
build();
FOR(i, 0, Q) {
int X = S[i], Y = E[i];
for (int j = 19; ~j; j--) {
if (~p[0][j][X] && p[0][j][X] >= L[i]) X = p[0][j][X];
if (~p[1][j][Y] && p[1][j][Y] <= R[i]) Y = p[1][j][Y];
}
A[i] = query(bounds[1][Y].first, bounds[1][Y].second, bounds[0][X].first, bounds[0][X].second);
}
return A;
}
Compilation message
werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:3:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define FOR(i, x, y) for (int i = x; i < y; i++)
werewolf.cpp:72:9:
FOR(i, 0, X.size()) {
~~~~~~~~~~~~~~
werewolf.cpp:72:5: note: in expansion of macro 'FOR'
FOR(i, 0, X.size()) {
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
64504 KB |
Output is correct |
2 |
Correct |
71 ms |
64620 KB |
Output is correct |
3 |
Correct |
61 ms |
64604 KB |
Output is correct |
4 |
Correct |
155 ms |
64476 KB |
Output is correct |
5 |
Correct |
60 ms |
64632 KB |
Output is correct |
6 |
Correct |
60 ms |
64536 KB |
Output is correct |
7 |
Correct |
59 ms |
64504 KB |
Output is correct |
8 |
Correct |
59 ms |
64632 KB |
Output is correct |
9 |
Correct |
59 ms |
64632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
64504 KB |
Output is correct |
2 |
Correct |
71 ms |
64620 KB |
Output is correct |
3 |
Correct |
61 ms |
64604 KB |
Output is correct |
4 |
Correct |
155 ms |
64476 KB |
Output is correct |
5 |
Correct |
60 ms |
64632 KB |
Output is correct |
6 |
Correct |
60 ms |
64536 KB |
Output is correct |
7 |
Correct |
59 ms |
64504 KB |
Output is correct |
8 |
Correct |
59 ms |
64632 KB |
Output is correct |
9 |
Correct |
59 ms |
64632 KB |
Output is correct |
10 |
Correct |
75 ms |
65556 KB |
Output is correct |
11 |
Correct |
68 ms |
65528 KB |
Output is correct |
12 |
Correct |
83 ms |
65572 KB |
Output is correct |
13 |
Correct |
73 ms |
65784 KB |
Output is correct |
14 |
Correct |
68 ms |
65784 KB |
Output is correct |
15 |
Correct |
68 ms |
65656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1131 ms |
124284 KB |
Output is correct |
2 |
Correct |
1080 ms |
129136 KB |
Output is correct |
3 |
Correct |
938 ms |
125184 KB |
Output is correct |
4 |
Correct |
1010 ms |
123588 KB |
Output is correct |
5 |
Correct |
1069 ms |
123508 KB |
Output is correct |
6 |
Correct |
1160 ms |
123348 KB |
Output is correct |
7 |
Correct |
1035 ms |
123376 KB |
Output is correct |
8 |
Correct |
952 ms |
129124 KB |
Output is correct |
9 |
Correct |
839 ms |
125140 KB |
Output is correct |
10 |
Correct |
673 ms |
123648 KB |
Output is correct |
11 |
Correct |
719 ms |
123508 KB |
Output is correct |
12 |
Correct |
908 ms |
124560 KB |
Output is correct |
13 |
Correct |
1185 ms |
136432 KB |
Output is correct |
14 |
Correct |
1163 ms |
136368 KB |
Output is correct |
15 |
Correct |
1483 ms |
136444 KB |
Output is correct |
16 |
Correct |
1219 ms |
136528 KB |
Output is correct |
17 |
Correct |
1044 ms |
124400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
64504 KB |
Output is correct |
2 |
Correct |
71 ms |
64620 KB |
Output is correct |
3 |
Correct |
61 ms |
64604 KB |
Output is correct |
4 |
Correct |
155 ms |
64476 KB |
Output is correct |
5 |
Correct |
60 ms |
64632 KB |
Output is correct |
6 |
Correct |
60 ms |
64536 KB |
Output is correct |
7 |
Correct |
59 ms |
64504 KB |
Output is correct |
8 |
Correct |
59 ms |
64632 KB |
Output is correct |
9 |
Correct |
59 ms |
64632 KB |
Output is correct |
10 |
Correct |
75 ms |
65556 KB |
Output is correct |
11 |
Correct |
68 ms |
65528 KB |
Output is correct |
12 |
Correct |
83 ms |
65572 KB |
Output is correct |
13 |
Correct |
73 ms |
65784 KB |
Output is correct |
14 |
Correct |
68 ms |
65784 KB |
Output is correct |
15 |
Correct |
68 ms |
65656 KB |
Output is correct |
16 |
Correct |
1131 ms |
124284 KB |
Output is correct |
17 |
Correct |
1080 ms |
129136 KB |
Output is correct |
18 |
Correct |
938 ms |
125184 KB |
Output is correct |
19 |
Correct |
1010 ms |
123588 KB |
Output is correct |
20 |
Correct |
1069 ms |
123508 KB |
Output is correct |
21 |
Correct |
1160 ms |
123348 KB |
Output is correct |
22 |
Correct |
1035 ms |
123376 KB |
Output is correct |
23 |
Correct |
952 ms |
129124 KB |
Output is correct |
24 |
Correct |
839 ms |
125140 KB |
Output is correct |
25 |
Correct |
673 ms |
123648 KB |
Output is correct |
26 |
Correct |
719 ms |
123508 KB |
Output is correct |
27 |
Correct |
908 ms |
124560 KB |
Output is correct |
28 |
Correct |
1185 ms |
136432 KB |
Output is correct |
29 |
Correct |
1163 ms |
136368 KB |
Output is correct |
30 |
Correct |
1483 ms |
136444 KB |
Output is correct |
31 |
Correct |
1219 ms |
136528 KB |
Output is correct |
32 |
Correct |
1044 ms |
124400 KB |
Output is correct |
33 |
Correct |
1403 ms |
125396 KB |
Output is correct |
34 |
Correct |
420 ms |
85592 KB |
Output is correct |
35 |
Correct |
1362 ms |
129088 KB |
Output is correct |
36 |
Correct |
1319 ms |
125332 KB |
Output is correct |
37 |
Correct |
1371 ms |
128112 KB |
Output is correct |
38 |
Correct |
1371 ms |
126320 KB |
Output is correct |
39 |
Correct |
1494 ms |
141468 KB |
Output is correct |
40 |
Correct |
1249 ms |
133556 KB |
Output is correct |
41 |
Correct |
1020 ms |
127368 KB |
Output is correct |
42 |
Correct |
766 ms |
125296 KB |
Output is correct |
43 |
Correct |
1169 ms |
134128 KB |
Output is correct |
44 |
Correct |
1242 ms |
127784 KB |
Output is correct |
45 |
Correct |
1092 ms |
140784 KB |
Output is correct |
46 |
Correct |
982 ms |
141168 KB |
Output is correct |
47 |
Correct |
1199 ms |
136192 KB |
Output is correct |
48 |
Correct |
1183 ms |
136056 KB |
Output is correct |
49 |
Correct |
1197 ms |
136048 KB |
Output is correct |
50 |
Correct |
1158 ms |
135892 KB |
Output is correct |
51 |
Correct |
1154 ms |
132720 KB |
Output is correct |
52 |
Correct |
1359 ms |
132528 KB |
Output is correct |