#include "werewolf.h"
#include "bits/stdc++.h"
using namespace std;
const int LOG = 20;
const int MAX_N = 4e5 + 5;
int n[2];
int p[MAX_N][2];
int val[MAX_N][2];
vector<int> adj[MAX_N], g[MAX_N][2];
int get(int v, int ver) {
return p[v][ver] = (p[v][ver] == v ? v : get(p[v][ver], ver));
}
void unite(int u, int v, int ver) {
u = get(u, ver), v = get(v, ver);
if (u == v) return;
int puv = n[ver]++;
g[puv][ver].push_back(u);
g[puv][ver].push_back(v);
p[puv][ver] = p[u][ver] = p[v][ver] = puv;
if (ver == 0) {
val[puv][ver] = min(val[u][ver], val[v][ver]);
} else {
val[puv][ver] = max(val[u][ver], val[v][ver]);
}
}
int cnt[2];
int dep[MAX_N][2], up[MAX_N][2][LOG];
int lx[MAX_N][2], rx[MAX_N][2], owner[MAX_N][2];
void dfs(int v, int ver) {
lx[v][ver] = ++cnt[ver];
owner[cnt[ver]][ver] = v;
for (int u : g[v][ver]) {
dep[u][ver] = dep[v][ver] + 1;
up[u][ver][0] = v;
for (int j = 1; j < LOG; ++j) {
up[u][ver][j] = up[up[u][ver][j - 1]][ver][j - 1];
}
dfs(u, ver);
}
rx[v][ver] = cnt[ver];
}
int tree[MAX_N];
int common[MAX_N];
vector<array<int, 4>> qs[MAX_N];
void upd(int i) {
while (i < MAX_N) {
tree[i]++;
i += i & -i;
}
}
int query(int i) {
int ret = 0;
while (i) {
ret += tree[i];
i -= i & -i;
}
return ret;
}
int query(int l, int r) {
return query(r) - query(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) {
for (int i = 0; i < (int) X.size(); ++i) {
adj[X[i]].push_back(Y[i]);
adj[Y[i]].push_back(X[i]);
}
n[0] = n[1] = N;
for (int i = 0; i < N; ++i) {
p[i][0] = p[i][1] = val[i][0] = val[i][1] = i;
}
for (int v = N - 1; v >= 0; --v) {
for (int u : adj[v]) {
if (u > v) {
unite(u, v, 0);
}
}
}
for (int v = 0; v < N; ++v) {
for (int u : adj[v]) {
if (u < v) {
unite(u, v, 1);
}
}
}
assert(n[0] == n[1] && n[0] == N * 2 - 1);
dfs(n[0] - 1, 0); dfs(n[1] - 1, 1);
int Q = (int) S.size();
for (int i = 0; i < Q; ++i) {
if (S[i] < L[i] || E[i] > R[i]) continue;
vector<int> r = {S[i], E[i]};
for (int j = LOG - 1; j >= 0; --j) {
if ((1 << j) <= dep[r[0]][0] && val[up[r[0]][0][j]][0] >= L[i]) {
r[0] = up[r[0]][0][j];
}
if ((1 << j) <= dep[r[1]][1] && up[r[1]][1][j] && val[up[r[1]][1][j]][1] <= R[i]) {
r[1] = up[r[1]][1][j];
}
}
int l1 = lx[r[0]][0], r1 = rx[r[0]][0];
int l2 = lx[r[1]][1], r2 = rx[r[1]][1];
qs[l2 - 1].push_back({l1, r1, -1, i});
qs[r2].push_back({l1, r1, 1, i});
}
for (int i = 1; i <= n[1]; ++i) {//eulerian
if (owner[i][1] < N) {
upd(lx[owner[i][1]][0]);
}
for (auto [l1, r1, v, j] : qs[i]) {
common[j] += query(l1, r1) * v;
}
}
vector<int> A(Q);
for (int i = 0; i < Q; ++i) {
A[i] = common[i] > 0;
}
return A;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
51800 KB |
Output is correct |
2 |
Correct |
13 ms |
51804 KB |
Output is correct |
3 |
Correct |
11 ms |
51804 KB |
Output is correct |
4 |
Correct |
10 ms |
51804 KB |
Output is correct |
5 |
Correct |
12 ms |
53852 KB |
Output is correct |
6 |
Correct |
12 ms |
51804 KB |
Output is correct |
7 |
Correct |
11 ms |
51804 KB |
Output is correct |
8 |
Correct |
10 ms |
51800 KB |
Output is correct |
9 |
Correct |
12 ms |
51804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
51800 KB |
Output is correct |
2 |
Correct |
13 ms |
51804 KB |
Output is correct |
3 |
Correct |
11 ms |
51804 KB |
Output is correct |
4 |
Correct |
10 ms |
51804 KB |
Output is correct |
5 |
Correct |
12 ms |
53852 KB |
Output is correct |
6 |
Correct |
12 ms |
51804 KB |
Output is correct |
7 |
Correct |
11 ms |
51804 KB |
Output is correct |
8 |
Correct |
10 ms |
51800 KB |
Output is correct |
9 |
Correct |
12 ms |
51804 KB |
Output is correct |
10 |
Correct |
16 ms |
53596 KB |
Output is correct |
11 |
Correct |
16 ms |
53340 KB |
Output is correct |
12 |
Correct |
15 ms |
53340 KB |
Output is correct |
13 |
Correct |
16 ms |
52828 KB |
Output is correct |
14 |
Correct |
18 ms |
53592 KB |
Output is correct |
15 |
Correct |
18 ms |
53424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
694 ms |
161128 KB |
Output is correct |
2 |
Correct |
711 ms |
171580 KB |
Output is correct |
3 |
Correct |
573 ms |
164284 KB |
Output is correct |
4 |
Correct |
573 ms |
160780 KB |
Output is correct |
5 |
Correct |
526 ms |
160684 KB |
Output is correct |
6 |
Correct |
642 ms |
160624 KB |
Output is correct |
7 |
Correct |
588 ms |
158776 KB |
Output is correct |
8 |
Correct |
632 ms |
171864 KB |
Output is correct |
9 |
Correct |
539 ms |
164104 KB |
Output is correct |
10 |
Correct |
476 ms |
159548 KB |
Output is correct |
11 |
Correct |
450 ms |
160796 KB |
Output is correct |
12 |
Correct |
528 ms |
159800 KB |
Output is correct |
13 |
Correct |
764 ms |
171488 KB |
Output is correct |
14 |
Correct |
756 ms |
171260 KB |
Output is correct |
15 |
Correct |
828 ms |
171532 KB |
Output is correct |
16 |
Correct |
802 ms |
171368 KB |
Output is correct |
17 |
Correct |
608 ms |
158936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
51800 KB |
Output is correct |
2 |
Correct |
13 ms |
51804 KB |
Output is correct |
3 |
Correct |
11 ms |
51804 KB |
Output is correct |
4 |
Correct |
10 ms |
51804 KB |
Output is correct |
5 |
Correct |
12 ms |
53852 KB |
Output is correct |
6 |
Correct |
12 ms |
51804 KB |
Output is correct |
7 |
Correct |
11 ms |
51804 KB |
Output is correct |
8 |
Correct |
10 ms |
51800 KB |
Output is correct |
9 |
Correct |
12 ms |
51804 KB |
Output is correct |
10 |
Correct |
16 ms |
53596 KB |
Output is correct |
11 |
Correct |
16 ms |
53340 KB |
Output is correct |
12 |
Correct |
15 ms |
53340 KB |
Output is correct |
13 |
Correct |
16 ms |
52828 KB |
Output is correct |
14 |
Correct |
18 ms |
53592 KB |
Output is correct |
15 |
Correct |
18 ms |
53424 KB |
Output is correct |
16 |
Correct |
694 ms |
161128 KB |
Output is correct |
17 |
Correct |
711 ms |
171580 KB |
Output is correct |
18 |
Correct |
573 ms |
164284 KB |
Output is correct |
19 |
Correct |
573 ms |
160780 KB |
Output is correct |
20 |
Correct |
526 ms |
160684 KB |
Output is correct |
21 |
Correct |
642 ms |
160624 KB |
Output is correct |
22 |
Correct |
588 ms |
158776 KB |
Output is correct |
23 |
Correct |
632 ms |
171864 KB |
Output is correct |
24 |
Correct |
539 ms |
164104 KB |
Output is correct |
25 |
Correct |
476 ms |
159548 KB |
Output is correct |
26 |
Correct |
450 ms |
160796 KB |
Output is correct |
27 |
Correct |
528 ms |
159800 KB |
Output is correct |
28 |
Correct |
764 ms |
171488 KB |
Output is correct |
29 |
Correct |
756 ms |
171260 KB |
Output is correct |
30 |
Correct |
828 ms |
171532 KB |
Output is correct |
31 |
Correct |
802 ms |
171368 KB |
Output is correct |
32 |
Correct |
608 ms |
158936 KB |
Output is correct |
33 |
Correct |
731 ms |
164176 KB |
Output is correct |
34 |
Correct |
225 ms |
80468 KB |
Output is correct |
35 |
Correct |
807 ms |
170760 KB |
Output is correct |
36 |
Correct |
703 ms |
162732 KB |
Output is correct |
37 |
Correct |
815 ms |
169140 KB |
Output is correct |
38 |
Correct |
711 ms |
163872 KB |
Output is correct |
39 |
Correct |
797 ms |
183352 KB |
Output is correct |
40 |
Correct |
756 ms |
168184 KB |
Output is correct |
41 |
Correct |
686 ms |
166240 KB |
Output is correct |
42 |
Correct |
530 ms |
160852 KB |
Output is correct |
43 |
Correct |
755 ms |
174616 KB |
Output is correct |
44 |
Correct |
671 ms |
168556 KB |
Output is correct |
45 |
Correct |
735 ms |
183956 KB |
Output is correct |
46 |
Correct |
688 ms |
183988 KB |
Output is correct |
47 |
Correct |
748 ms |
171284 KB |
Output is correct |
48 |
Correct |
774 ms |
171184 KB |
Output is correct |
49 |
Correct |
757 ms |
171420 KB |
Output is correct |
50 |
Correct |
725 ms |
171280 KB |
Output is correct |
51 |
Correct |
694 ms |
170136 KB |
Output is correct |
52 |
Correct |
674 ms |
170324 KB |
Output is correct |