#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
//10:20
const int mxN = 2e5;
template <class T>
struct KRT {
int ncnt, dsu[2*mxN], val[2*mxN], anc[2*mxN][19];
vector<int> g[2*mxN];
T cmp;
int f(int x) {return dsu[x] == x ? x : dsu[x] = f(dsu[x]);}
KRT (int n, vector<int> &u, vector<int> &v) : ncnt(n) {
iota(begin(dsu), end(dsu), 0);
vector<int> order(u.size());
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int a, int b) {return cmp(max(u[a], v[a], cmp), max(u[b], v[b], cmp));});
for (int e: order) {
int a = f(u[e]), b = f(v[e]);
if (a != b) {
anc[a][0] = anc[b][0] = dsu[b] = dsu[a] = ncnt;
val[ncnt] = max(u[e], v[e], cmp);
g[ncnt].push_back(a);
g[ncnt].push_back(b);
ncnt++;
}
}
anc[ncnt-1][0] = ncnt-1;
for (int i = 1; i < 19; ++i) for (int j = 0; j < ncnt; ++j) anc[j][i] = ncnt-1;
for (int i = 1; i < 19; ++i) {
for (int j = 0; j < ncnt; ++j) {
anc[j][i] = anc[anc[j][i-1]][i-1];
}
}
}
int thresh(int x, int v) {
for (int i = 19; i--;) {
if (!cmp(v,val[anc[x][i]])) x = anc[x][i];
}
return x;
}
};
int tcnt, st[2*mxN], en[2*mxN];
void dfs1(int u, KRT<less<int>> &k) {
st[u] = tcnt++;
for (int v: k.g[u]) dfs1(v, k);
en[u] = tcnt;
}
struct qry {int l, r, id;};
vector<qry> qrys[2*mxN];
vector<int> ans;
set<int> sts[2*mxN];
void dfs2(int u, KRT<greater<int>> &k) {
for (int v: k.g[u]) {
dfs2(v, k);
if (sts[u].size() < sts[v].size()) swap(sts[u], sts[v]);
sts[u].merge(sts[v]);
}
for (qry q: qrys[u]) {
auto it = sts[u].lower_bound(q.l);
ans[q.id] = it != sts[u].end() && *it < q.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) {
int Q = S.size();
ans.resize(Q);
KRT<less<int>> wolf(N,X,Y);
KRT<greater<int>> human(N,X,Y);
dfs1(wolf.ncnt-1, wolf);
for (int i = 0; i < N; ++i) sts[i].insert(st[i]);
for (int i = 0; i < Q; ++i) {
int x = wolf.thresh(E[i], R[i]);
qrys[human.thresh(S[i], L[i])].push_back({st[x], en[x], i});
}
dfs2(human.ncnt-1, human);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
112972 KB |
Output is correct |
2 |
Correct |
63 ms |
112996 KB |
Output is correct |
3 |
Correct |
56 ms |
112924 KB |
Output is correct |
4 |
Correct |
55 ms |
112988 KB |
Output is correct |
5 |
Correct |
56 ms |
112964 KB |
Output is correct |
6 |
Correct |
55 ms |
113028 KB |
Output is correct |
7 |
Correct |
56 ms |
113116 KB |
Output is correct |
8 |
Correct |
57 ms |
113016 KB |
Output is correct |
9 |
Correct |
55 ms |
113024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
112972 KB |
Output is correct |
2 |
Correct |
63 ms |
112996 KB |
Output is correct |
3 |
Correct |
56 ms |
112924 KB |
Output is correct |
4 |
Correct |
55 ms |
112988 KB |
Output is correct |
5 |
Correct |
56 ms |
112964 KB |
Output is correct |
6 |
Correct |
55 ms |
113028 KB |
Output is correct |
7 |
Correct |
56 ms |
113116 KB |
Output is correct |
8 |
Correct |
57 ms |
113016 KB |
Output is correct |
9 |
Correct |
55 ms |
113024 KB |
Output is correct |
10 |
Correct |
62 ms |
113796 KB |
Output is correct |
11 |
Correct |
69 ms |
113648 KB |
Output is correct |
12 |
Correct |
65 ms |
113588 KB |
Output is correct |
13 |
Correct |
69 ms |
113692 KB |
Output is correct |
14 |
Correct |
65 ms |
113672 KB |
Output is correct |
15 |
Correct |
65 ms |
113672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1241 ms |
153160 KB |
Output is correct |
2 |
Correct |
1190 ms |
156280 KB |
Output is correct |
3 |
Correct |
1085 ms |
161912 KB |
Output is correct |
4 |
Correct |
1098 ms |
160808 KB |
Output is correct |
5 |
Correct |
1128 ms |
161044 KB |
Output is correct |
6 |
Correct |
1190 ms |
161380 KB |
Output is correct |
7 |
Correct |
1184 ms |
160892 KB |
Output is correct |
8 |
Correct |
1120 ms |
164808 KB |
Output is correct |
9 |
Correct |
991 ms |
161732 KB |
Output is correct |
10 |
Correct |
937 ms |
160708 KB |
Output is correct |
11 |
Correct |
963 ms |
160672 KB |
Output is correct |
12 |
Correct |
1027 ms |
160452 KB |
Output is correct |
13 |
Correct |
1306 ms |
174076 KB |
Output is correct |
14 |
Correct |
1313 ms |
174044 KB |
Output is correct |
15 |
Correct |
1290 ms |
174016 KB |
Output is correct |
16 |
Correct |
1345 ms |
174164 KB |
Output is correct |
17 |
Correct |
1228 ms |
161056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
112972 KB |
Output is correct |
2 |
Correct |
63 ms |
112996 KB |
Output is correct |
3 |
Correct |
56 ms |
112924 KB |
Output is correct |
4 |
Correct |
55 ms |
112988 KB |
Output is correct |
5 |
Correct |
56 ms |
112964 KB |
Output is correct |
6 |
Correct |
55 ms |
113028 KB |
Output is correct |
7 |
Correct |
56 ms |
113116 KB |
Output is correct |
8 |
Correct |
57 ms |
113016 KB |
Output is correct |
9 |
Correct |
55 ms |
113024 KB |
Output is correct |
10 |
Correct |
62 ms |
113796 KB |
Output is correct |
11 |
Correct |
69 ms |
113648 KB |
Output is correct |
12 |
Correct |
65 ms |
113588 KB |
Output is correct |
13 |
Correct |
69 ms |
113692 KB |
Output is correct |
14 |
Correct |
65 ms |
113672 KB |
Output is correct |
15 |
Correct |
65 ms |
113672 KB |
Output is correct |
16 |
Correct |
1241 ms |
153160 KB |
Output is correct |
17 |
Correct |
1190 ms |
156280 KB |
Output is correct |
18 |
Correct |
1085 ms |
161912 KB |
Output is correct |
19 |
Correct |
1098 ms |
160808 KB |
Output is correct |
20 |
Correct |
1128 ms |
161044 KB |
Output is correct |
21 |
Correct |
1190 ms |
161380 KB |
Output is correct |
22 |
Correct |
1184 ms |
160892 KB |
Output is correct |
23 |
Correct |
1120 ms |
164808 KB |
Output is correct |
24 |
Correct |
991 ms |
161732 KB |
Output is correct |
25 |
Correct |
937 ms |
160708 KB |
Output is correct |
26 |
Correct |
963 ms |
160672 KB |
Output is correct |
27 |
Correct |
1027 ms |
160452 KB |
Output is correct |
28 |
Correct |
1306 ms |
174076 KB |
Output is correct |
29 |
Correct |
1313 ms |
174044 KB |
Output is correct |
30 |
Correct |
1290 ms |
174016 KB |
Output is correct |
31 |
Correct |
1345 ms |
174164 KB |
Output is correct |
32 |
Correct |
1228 ms |
161056 KB |
Output is correct |
33 |
Correct |
1408 ms |
164596 KB |
Output is correct |
34 |
Correct |
536 ms |
142736 KB |
Output is correct |
35 |
Correct |
1486 ms |
172592 KB |
Output is correct |
36 |
Correct |
1298 ms |
163452 KB |
Output is correct |
37 |
Correct |
1467 ms |
170792 KB |
Output is correct |
38 |
Correct |
1351 ms |
165108 KB |
Output is correct |
39 |
Correct |
1364 ms |
167052 KB |
Output is correct |
40 |
Correct |
1456 ms |
173480 KB |
Output is correct |
41 |
Correct |
1198 ms |
168548 KB |
Output is correct |
42 |
Correct |
1086 ms |
162456 KB |
Output is correct |
43 |
Correct |
1458 ms |
178068 KB |
Output is correct |
44 |
Correct |
1399 ms |
170260 KB |
Output is correct |
45 |
Correct |
1164 ms |
166692 KB |
Output is correct |
46 |
Correct |
1231 ms |
166080 KB |
Output is correct |
47 |
Correct |
1332 ms |
174296 KB |
Output is correct |
48 |
Correct |
1294 ms |
174036 KB |
Output is correct |
49 |
Correct |
1330 ms |
174268 KB |
Output is correct |
50 |
Correct |
1310 ms |
174140 KB |
Output is correct |
51 |
Correct |
1389 ms |
173916 KB |
Output is correct |
52 |
Correct |
1350 ms |
173960 KB |
Output is correct |