#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+5;
typedef pair<int, int> pii;
int n, m, q;
vector<int> edges[MAXN];
vector<int> dsutree[MAXN];
int uf[MAXN];
int order[MAXN];
pii range[MAXN];
vector<int> query_nodes[MAXN];
vector<int> uf2;
vector<int> lquery[MAXN];
vector<int> rquery[MAXN];
int tree_node[MAXN];
int t = 0;
int find(int i) {
return uf[i] == i ? i : uf[i] = find(uf[i]);
}
void merge(int i, int j) {
j = find(j);
if (i == j) return;
assert(i > j);
uf[j] = i;
dsutree[i].push_back(j);
}
class stree;
unordered_set<int> cont[MAXN];
int id[2*MAXN];
void make_decomp() {
for (int i = n; i < 2*n; i++) id[i] = order[i-n];
for (int i = 1; i < n; i++) {
id[i] = t++;
}
for (int i = n; i < 2*n; i++) {
for (int cur = i; cur > 0; cur /= 2) {
cont[order[i-n]].insert(id[cur]);
}
// cerr << order[i-n] << ": \n";
// for (int v: cont[order[i-n]]) cerr << v << ' ';
// cerr << '\n';
}
for (int i = 0; i < q; i++) {
for (int l = range[tree_node[i]].first+n, r = range[tree_node[i]].second+1+n; r > l; l /= 2, r /= 2) {
if (l & 1) query_nodes[i].push_back(id[l++]);
if (r & 1) query_nodes[i].push_back(id[--r]);
}
}
}
stree *tree;
void dfs(int cur) {
range[cur].first = t;
order[t++] = cur;
for (int nxt: dsutree[cur]) dfs(nxt);
range[cur].second = t-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) {
q = S.size();
n = N;
m = X.size();
for (int i = 0; i < q; i++) {
lquery[L[i]].push_back(i);
rquery[R[i]].push_back(i);
}
for (int i = 0; i < m; i++) {
edges[X[i]].push_back(Y[i]);
edges[Y[i]].push_back(X[i]);
}
iota(uf, uf+n, 0);
for (int i = 0; i < n; i++) {
for (int nxt: edges[i]) {
if (nxt > i) continue;
merge(i, nxt);
}
for (int v: rquery[i]) tree_node[v] = find(E[v]);
}
dfs(n-1);
// assert(false);
// tree = new stree(); // really thick
// // assert(false);
// for (int i = 0; i < q; i++) {
// tree->decompose(range[tree_node[i]].first, range[tree_node[i]].second, query_nodes[i]);
// assert(query_nodes[i].size() < 40);
// }
make_decomp();
// assert(false);
vector<int> uf(t);
iota(uf.begin(), uf.end(), 0);
// for (int i = 0; i < n; i++) {
// // assert(cont[i].find(i) != cont[i].end());
// // assert(cont[i].size() < 20);
// }
vector<int> ans(q, 0);
for (int i = n-1; i >= 0; i--) {
for (int nxt: edges[i]) {
if (nxt < i) continue;
int v = uf[nxt];
int u = uf[i];
if (u == v) continue;
if (cont[u].size() < cont[v].size()) swap(u, v);
for (int val: cont[v]) {
cont[u].insert(val);
uf[val] = u;
}
cont[v].clear();
}
for (int v: lquery[i]) {
for (int check: query_nodes[v]) {
if (cont[uf[S[v]]].find(check) != cont[uf[S[v]]].end()) {
ans[v] = 1;
break;
}
}
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
34772 KB |
Output is correct |
2 |
Correct |
16 ms |
34772 KB |
Output is correct |
3 |
Correct |
16 ms |
34800 KB |
Output is correct |
4 |
Correct |
16 ms |
34756 KB |
Output is correct |
5 |
Correct |
18 ms |
34732 KB |
Output is correct |
6 |
Correct |
17 ms |
34832 KB |
Output is correct |
7 |
Correct |
20 ms |
34816 KB |
Output is correct |
8 |
Correct |
17 ms |
34772 KB |
Output is correct |
9 |
Correct |
17 ms |
34772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
34772 KB |
Output is correct |
2 |
Correct |
16 ms |
34772 KB |
Output is correct |
3 |
Correct |
16 ms |
34800 KB |
Output is correct |
4 |
Correct |
16 ms |
34756 KB |
Output is correct |
5 |
Correct |
18 ms |
34732 KB |
Output is correct |
6 |
Correct |
17 ms |
34832 KB |
Output is correct |
7 |
Correct |
20 ms |
34816 KB |
Output is correct |
8 |
Correct |
17 ms |
34772 KB |
Output is correct |
9 |
Correct |
17 ms |
34772 KB |
Output is correct |
10 |
Correct |
24 ms |
37280 KB |
Output is correct |
11 |
Correct |
24 ms |
37176 KB |
Output is correct |
12 |
Correct |
24 ms |
37332 KB |
Output is correct |
13 |
Correct |
26 ms |
37604 KB |
Output is correct |
14 |
Correct |
30 ms |
38036 KB |
Output is correct |
15 |
Correct |
26 ms |
37392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1678 ms |
269396 KB |
Output is correct |
2 |
Correct |
904 ms |
275928 KB |
Output is correct |
3 |
Correct |
1000 ms |
277972 KB |
Output is correct |
4 |
Correct |
1262 ms |
284508 KB |
Output is correct |
5 |
Correct |
1443 ms |
286064 KB |
Output is correct |
6 |
Correct |
1713 ms |
285596 KB |
Output is correct |
7 |
Correct |
1754 ms |
288500 KB |
Output is correct |
8 |
Correct |
900 ms |
275776 KB |
Output is correct |
9 |
Correct |
962 ms |
273828 KB |
Output is correct |
10 |
Correct |
1137 ms |
272460 KB |
Output is correct |
11 |
Correct |
1319 ms |
273240 KB |
Output is correct |
12 |
Correct |
1689 ms |
284688 KB |
Output is correct |
13 |
Correct |
1043 ms |
277648 KB |
Output is correct |
14 |
Correct |
1016 ms |
276376 KB |
Output is correct |
15 |
Correct |
1028 ms |
277652 KB |
Output is correct |
16 |
Correct |
1016 ms |
279036 KB |
Output is correct |
17 |
Correct |
1674 ms |
285040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
34772 KB |
Output is correct |
2 |
Correct |
16 ms |
34772 KB |
Output is correct |
3 |
Correct |
16 ms |
34800 KB |
Output is correct |
4 |
Correct |
16 ms |
34756 KB |
Output is correct |
5 |
Correct |
18 ms |
34732 KB |
Output is correct |
6 |
Correct |
17 ms |
34832 KB |
Output is correct |
7 |
Correct |
20 ms |
34816 KB |
Output is correct |
8 |
Correct |
17 ms |
34772 KB |
Output is correct |
9 |
Correct |
17 ms |
34772 KB |
Output is correct |
10 |
Correct |
24 ms |
37280 KB |
Output is correct |
11 |
Correct |
24 ms |
37176 KB |
Output is correct |
12 |
Correct |
24 ms |
37332 KB |
Output is correct |
13 |
Correct |
26 ms |
37604 KB |
Output is correct |
14 |
Correct |
30 ms |
38036 KB |
Output is correct |
15 |
Correct |
26 ms |
37392 KB |
Output is correct |
16 |
Correct |
1678 ms |
269396 KB |
Output is correct |
17 |
Correct |
904 ms |
275928 KB |
Output is correct |
18 |
Correct |
1000 ms |
277972 KB |
Output is correct |
19 |
Correct |
1262 ms |
284508 KB |
Output is correct |
20 |
Correct |
1443 ms |
286064 KB |
Output is correct |
21 |
Correct |
1713 ms |
285596 KB |
Output is correct |
22 |
Correct |
1754 ms |
288500 KB |
Output is correct |
23 |
Correct |
900 ms |
275776 KB |
Output is correct |
24 |
Correct |
962 ms |
273828 KB |
Output is correct |
25 |
Correct |
1137 ms |
272460 KB |
Output is correct |
26 |
Correct |
1319 ms |
273240 KB |
Output is correct |
27 |
Correct |
1689 ms |
284688 KB |
Output is correct |
28 |
Correct |
1043 ms |
277648 KB |
Output is correct |
29 |
Correct |
1016 ms |
276376 KB |
Output is correct |
30 |
Correct |
1028 ms |
277652 KB |
Output is correct |
31 |
Correct |
1016 ms |
279036 KB |
Output is correct |
32 |
Correct |
1674 ms |
285040 KB |
Output is correct |
33 |
Correct |
1567 ms |
276612 KB |
Output is correct |
34 |
Correct |
227 ms |
84200 KB |
Output is correct |
35 |
Correct |
1459 ms |
285712 KB |
Output is correct |
36 |
Correct |
1541 ms |
273920 KB |
Output is correct |
37 |
Correct |
1454 ms |
283028 KB |
Output is correct |
38 |
Correct |
1545 ms |
279788 KB |
Output is correct |
39 |
Correct |
2655 ms |
361680 KB |
Output is correct |
40 |
Correct |
1483 ms |
290540 KB |
Output is correct |
41 |
Correct |
1418 ms |
279276 KB |
Output is correct |
42 |
Correct |
1404 ms |
269652 KB |
Output is correct |
43 |
Correct |
1457 ms |
296588 KB |
Output is correct |
44 |
Correct |
1429 ms |
282416 KB |
Output is correct |
45 |
Correct |
2024 ms |
334484 KB |
Output is correct |
46 |
Correct |
2516 ms |
361648 KB |
Output is correct |
47 |
Correct |
1024 ms |
276492 KB |
Output is correct |
48 |
Correct |
1032 ms |
277696 KB |
Output is correct |
49 |
Correct |
1034 ms |
276948 KB |
Output is correct |
50 |
Correct |
1029 ms |
276400 KB |
Output is correct |
51 |
Correct |
1463 ms |
292788 KB |
Output is correct |
52 |
Correct |
1418 ms |
290152 KB |
Output is correct |