#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 |
13 ms |
51800 KB |
Output is correct |
2 |
Correct |
10 ms |
51936 KB |
Output is correct |
3 |
Correct |
11 ms |
51992 KB |
Output is correct |
4 |
Correct |
10 ms |
51804 KB |
Output is correct |
5 |
Correct |
10 ms |
53852 KB |
Output is correct |
6 |
Correct |
10 ms |
51804 KB |
Output is correct |
7 |
Correct |
10 ms |
51804 KB |
Output is correct |
8 |
Correct |
10 ms |
51892 KB |
Output is correct |
9 |
Correct |
11 ms |
51800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
51800 KB |
Output is correct |
2 |
Correct |
10 ms |
51936 KB |
Output is correct |
3 |
Correct |
11 ms |
51992 KB |
Output is correct |
4 |
Correct |
10 ms |
51804 KB |
Output is correct |
5 |
Correct |
10 ms |
53852 KB |
Output is correct |
6 |
Correct |
10 ms |
51804 KB |
Output is correct |
7 |
Correct |
10 ms |
51804 KB |
Output is correct |
8 |
Correct |
10 ms |
51892 KB |
Output is correct |
9 |
Correct |
11 ms |
51800 KB |
Output is correct |
10 |
Correct |
17 ms |
53596 KB |
Output is correct |
11 |
Correct |
16 ms |
53596 KB |
Output is correct |
12 |
Correct |
15 ms |
53392 KB |
Output is correct |
13 |
Correct |
15 ms |
53192 KB |
Output is correct |
14 |
Correct |
15 ms |
53700 KB |
Output is correct |
15 |
Correct |
16 ms |
53596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
656 ms |
169396 KB |
Output is correct |
2 |
Correct |
645 ms |
179840 KB |
Output is correct |
3 |
Correct |
560 ms |
172432 KB |
Output is correct |
4 |
Correct |
531 ms |
169316 KB |
Output is correct |
5 |
Correct |
539 ms |
169300 KB |
Output is correct |
6 |
Correct |
602 ms |
169296 KB |
Output is correct |
7 |
Correct |
580 ms |
166992 KB |
Output is correct |
8 |
Correct |
606 ms |
180516 KB |
Output is correct |
9 |
Correct |
529 ms |
172976 KB |
Output is correct |
10 |
Correct |
438 ms |
167872 KB |
Output is correct |
11 |
Correct |
443 ms |
169044 KB |
Output is correct |
12 |
Correct |
512 ms |
168364 KB |
Output is correct |
13 |
Correct |
745 ms |
179796 KB |
Output is correct |
14 |
Correct |
753 ms |
179544 KB |
Output is correct |
15 |
Correct |
728 ms |
179616 KB |
Output is correct |
16 |
Correct |
743 ms |
179868 KB |
Output is correct |
17 |
Correct |
586 ms |
167176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
51800 KB |
Output is correct |
2 |
Correct |
10 ms |
51936 KB |
Output is correct |
3 |
Correct |
11 ms |
51992 KB |
Output is correct |
4 |
Correct |
10 ms |
51804 KB |
Output is correct |
5 |
Correct |
10 ms |
53852 KB |
Output is correct |
6 |
Correct |
10 ms |
51804 KB |
Output is correct |
7 |
Correct |
10 ms |
51804 KB |
Output is correct |
8 |
Correct |
10 ms |
51892 KB |
Output is correct |
9 |
Correct |
11 ms |
51800 KB |
Output is correct |
10 |
Correct |
17 ms |
53596 KB |
Output is correct |
11 |
Correct |
16 ms |
53596 KB |
Output is correct |
12 |
Correct |
15 ms |
53392 KB |
Output is correct |
13 |
Correct |
15 ms |
53192 KB |
Output is correct |
14 |
Correct |
15 ms |
53700 KB |
Output is correct |
15 |
Correct |
16 ms |
53596 KB |
Output is correct |
16 |
Correct |
656 ms |
169396 KB |
Output is correct |
17 |
Correct |
645 ms |
179840 KB |
Output is correct |
18 |
Correct |
560 ms |
172432 KB |
Output is correct |
19 |
Correct |
531 ms |
169316 KB |
Output is correct |
20 |
Correct |
539 ms |
169300 KB |
Output is correct |
21 |
Correct |
602 ms |
169296 KB |
Output is correct |
22 |
Correct |
580 ms |
166992 KB |
Output is correct |
23 |
Correct |
606 ms |
180516 KB |
Output is correct |
24 |
Correct |
529 ms |
172976 KB |
Output is correct |
25 |
Correct |
438 ms |
167872 KB |
Output is correct |
26 |
Correct |
443 ms |
169044 KB |
Output is correct |
27 |
Correct |
512 ms |
168364 KB |
Output is correct |
28 |
Correct |
745 ms |
179796 KB |
Output is correct |
29 |
Correct |
753 ms |
179544 KB |
Output is correct |
30 |
Correct |
728 ms |
179616 KB |
Output is correct |
31 |
Correct |
743 ms |
179868 KB |
Output is correct |
32 |
Correct |
586 ms |
167176 KB |
Output is correct |
33 |
Correct |
743 ms |
172428 KB |
Output is correct |
34 |
Correct |
226 ms |
92076 KB |
Output is correct |
35 |
Correct |
796 ms |
179540 KB |
Output is correct |
36 |
Correct |
690 ms |
171308 KB |
Output is correct |
37 |
Correct |
787 ms |
177884 KB |
Output is correct |
38 |
Correct |
704 ms |
172780 KB |
Output is correct |
39 |
Correct |
775 ms |
192020 KB |
Output is correct |
40 |
Correct |
760 ms |
179860 KB |
Output is correct |
41 |
Correct |
618 ms |
174616 KB |
Output is correct |
42 |
Correct |
528 ms |
169556 KB |
Output is correct |
43 |
Correct |
749 ms |
184456 KB |
Output is correct |
44 |
Correct |
688 ms |
177116 KB |
Output is correct |
45 |
Correct |
698 ms |
192700 KB |
Output is correct |
46 |
Correct |
704 ms |
192196 KB |
Output is correct |
47 |
Correct |
730 ms |
179836 KB |
Output is correct |
48 |
Correct |
746 ms |
179596 KB |
Output is correct |
49 |
Correct |
732 ms |
179792 KB |
Output is correct |
50 |
Correct |
723 ms |
179628 KB |
Output is correct |
51 |
Correct |
674 ms |
181600 KB |
Output is correct |
52 |
Correct |
713 ms |
181664 KB |
Output is correct |