#include "werewolf.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn = 2e5 + 20;
const int maxb = 20;
vector<int> adj[maxn] , tree[2][maxn] , query[maxn];
int px[maxn] , par[2][maxn][maxb] , st[2][maxn] , ft[2][maxn] , id , rst[2][maxn];
int l1[maxn] , r1[maxn] , l2[maxn] , r2[maxn];
int root(int v)
{
return px[v] < 0? v : px[v] = root(px[v]);
}
void dfs(int v , int b , int p = -1)
{
if(p == -1)
{
for(int i = 0; i < maxb; i++)
par[b][v][i] = v;
id = -1;
}
st[b][v] = ++id;
rst[b][id] = v;
for(auto u : tree[b][v])
{
par[b][u][0] = v;
for(int i = 1; i < maxb; i++)
par[b][u][i] = par[b][par[b][u][i - 1]][i - 1];
dfs(u , b , v);
}
ft[b][v] = id;
}
int n , mx[maxn * 4];
void upd(int p , int val , int s = 0 , int e = n , int v = 1)
{
if(e - s < 2)
{
mx[v] = val;
return;
}
int m = (s + e) / 2;
if(p < m)
upd(p , val , s , m , 2 * v);
else
upd(p , val , m , e , 2 * v + 1);
mx[v] = max(mx[2 * v] , mx[2 * v + 1]);
}
int get(int l , int r , int s = 0 , int e = n , int v = 1)
{
if(l <= s && e <= r)
return mx[v];
if(r <= s || e <= l)
return -1;
int m = (s + e) / 2;
return max(get(l , r , s , m , 2 * v) , get(l , r , m , e , 2 * v + 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)
{
n = N;
for(int i = 0; i < (int)X.size(); i++)
{
int a = X[i] , b = Y[i];
adj[a].pb(b);
adj[b].pb(a);
}
memset(px , -1 , sizeof px);
for(int v = 0; v < n; v++)
for(auto u : adj[v])
if(u < v)
{
u = root(u);
if(u != v)
tree[0][v].pb(u) , px[u] = v;
}
memset(px , -1 , sizeof px);
for(int v = n - 1; v >= 0; v--)
for(auto u : adj[v])
if(u > v)
{
u = root(u);
if(u != v)
tree[1][v].pb(u) , px[u] = v;
}
dfs(n - 1 , 0) , dfs(0 , 1);
int q = S.size();
for(int i = 0; i < q; i++)
{
int s = S[i] , e = E[i];
for(int j = maxb - 1; j >= 0; j--)
if(par[0][e][j] <= R[i])
e = par[0][e][j];
for(int j = maxb - 1; j >= 0; j--)
if(par[1][s][j] >= L[i])
s = par[1][s][j];
l1[i] = st[0][e] , r1[i] = ft[0][e];
l2[i] = st[1][s] , r2[i] = ft[1][s];
query[r1[i]].pb(i);
}
memset(mx , -1 , sizeof mx);
vector<int> ans(q);
for(int i = 0; i < n; i++)
{
int v = rst[0][i];
upd(st[1][v] , i);
for(auto ind : query[i])
ans[ind] = get(l2[ind] , r2[ind] + 1) >= l1[ind];
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23160 KB |
Output is correct |
2 |
Correct |
23 ms |
23160 KB |
Output is correct |
3 |
Correct |
23 ms |
23032 KB |
Output is correct |
4 |
Correct |
23 ms |
23032 KB |
Output is correct |
5 |
Correct |
24 ms |
23160 KB |
Output is correct |
6 |
Correct |
23 ms |
23160 KB |
Output is correct |
7 |
Correct |
27 ms |
23160 KB |
Output is correct |
8 |
Correct |
24 ms |
23160 KB |
Output is correct |
9 |
Correct |
23 ms |
23160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23160 KB |
Output is correct |
2 |
Correct |
23 ms |
23160 KB |
Output is correct |
3 |
Correct |
23 ms |
23032 KB |
Output is correct |
4 |
Correct |
23 ms |
23032 KB |
Output is correct |
5 |
Correct |
24 ms |
23160 KB |
Output is correct |
6 |
Correct |
23 ms |
23160 KB |
Output is correct |
7 |
Correct |
27 ms |
23160 KB |
Output is correct |
8 |
Correct |
24 ms |
23160 KB |
Output is correct |
9 |
Correct |
23 ms |
23160 KB |
Output is correct |
10 |
Correct |
31 ms |
24312 KB |
Output is correct |
11 |
Correct |
30 ms |
24184 KB |
Output is correct |
12 |
Correct |
30 ms |
24184 KB |
Output is correct |
13 |
Correct |
35 ms |
24568 KB |
Output is correct |
14 |
Correct |
35 ms |
24568 KB |
Output is correct |
15 |
Correct |
32 ms |
24428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
916 ms |
97468 KB |
Output is correct |
2 |
Correct |
904 ms |
104056 KB |
Output is correct |
3 |
Correct |
805 ms |
99220 KB |
Output is correct |
4 |
Correct |
737 ms |
97236 KB |
Output is correct |
5 |
Correct |
738 ms |
97108 KB |
Output is correct |
6 |
Correct |
858 ms |
97436 KB |
Output is correct |
7 |
Correct |
875 ms |
97140 KB |
Output is correct |
8 |
Correct |
799 ms |
104004 KB |
Output is correct |
9 |
Correct |
637 ms |
99028 KB |
Output is correct |
10 |
Correct |
610 ms |
96888 KB |
Output is correct |
11 |
Correct |
689 ms |
97144 KB |
Output is correct |
12 |
Correct |
745 ms |
96628 KB |
Output is correct |
13 |
Correct |
1004 ms |
110056 KB |
Output is correct |
14 |
Correct |
1097 ms |
109924 KB |
Output is correct |
15 |
Correct |
935 ms |
109952 KB |
Output is correct |
16 |
Correct |
877 ms |
110172 KB |
Output is correct |
17 |
Correct |
745 ms |
97040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
23160 KB |
Output is correct |
2 |
Correct |
23 ms |
23160 KB |
Output is correct |
3 |
Correct |
23 ms |
23032 KB |
Output is correct |
4 |
Correct |
23 ms |
23032 KB |
Output is correct |
5 |
Correct |
24 ms |
23160 KB |
Output is correct |
6 |
Correct |
23 ms |
23160 KB |
Output is correct |
7 |
Correct |
27 ms |
23160 KB |
Output is correct |
8 |
Correct |
24 ms |
23160 KB |
Output is correct |
9 |
Correct |
23 ms |
23160 KB |
Output is correct |
10 |
Correct |
31 ms |
24312 KB |
Output is correct |
11 |
Correct |
30 ms |
24184 KB |
Output is correct |
12 |
Correct |
30 ms |
24184 KB |
Output is correct |
13 |
Correct |
35 ms |
24568 KB |
Output is correct |
14 |
Correct |
35 ms |
24568 KB |
Output is correct |
15 |
Correct |
32 ms |
24428 KB |
Output is correct |
16 |
Correct |
916 ms |
97468 KB |
Output is correct |
17 |
Correct |
904 ms |
104056 KB |
Output is correct |
18 |
Correct |
805 ms |
99220 KB |
Output is correct |
19 |
Correct |
737 ms |
97236 KB |
Output is correct |
20 |
Correct |
738 ms |
97108 KB |
Output is correct |
21 |
Correct |
858 ms |
97436 KB |
Output is correct |
22 |
Correct |
875 ms |
97140 KB |
Output is correct |
23 |
Correct |
799 ms |
104004 KB |
Output is correct |
24 |
Correct |
637 ms |
99028 KB |
Output is correct |
25 |
Correct |
610 ms |
96888 KB |
Output is correct |
26 |
Correct |
689 ms |
97144 KB |
Output is correct |
27 |
Correct |
745 ms |
96628 KB |
Output is correct |
28 |
Correct |
1004 ms |
110056 KB |
Output is correct |
29 |
Correct |
1097 ms |
109924 KB |
Output is correct |
30 |
Correct |
935 ms |
109952 KB |
Output is correct |
31 |
Correct |
877 ms |
110172 KB |
Output is correct |
32 |
Correct |
745 ms |
97040 KB |
Output is correct |
33 |
Correct |
891 ms |
98856 KB |
Output is correct |
34 |
Correct |
371 ms |
58704 KB |
Output is correct |
35 |
Correct |
963 ms |
103416 KB |
Output is correct |
36 |
Correct |
847 ms |
98620 KB |
Output is correct |
37 |
Correct |
921 ms |
102080 KB |
Output is correct |
38 |
Correct |
959 ms |
99648 KB |
Output is correct |
39 |
Correct |
951 ms |
116692 KB |
Output is correct |
40 |
Correct |
1010 ms |
109664 KB |
Output is correct |
41 |
Correct |
793 ms |
100572 KB |
Output is correct |
42 |
Correct |
640 ms |
97912 KB |
Output is correct |
43 |
Correct |
1053 ms |
109656 KB |
Output is correct |
44 |
Correct |
877 ms |
101504 KB |
Output is correct |
45 |
Correct |
837 ms |
117080 KB |
Output is correct |
46 |
Correct |
753 ms |
116588 KB |
Output is correct |
47 |
Correct |
809 ms |
110228 KB |
Output is correct |
48 |
Correct |
817 ms |
109980 KB |
Output is correct |
49 |
Correct |
857 ms |
110384 KB |
Output is correct |
50 |
Correct |
1020 ms |
110036 KB |
Output is correct |
51 |
Correct |
1212 ms |
109672 KB |
Output is correct |
52 |
Correct |
927 ms |
109464 KB |
Output is correct |