#include "werewolf.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int logn = log2(maxn) + 1;
vector<int> e[maxn] , adj[maxn] , radj[maxn];
int lab[maxn];
int in[2][maxn] , out[2][maxn] , id[2][maxn];
int nTime = 0;
int P[2][maxn][logn];
int n;
#define pb push_back
void DFS(int u , int par , vector<int> adj[] , int in[] , int out[] , int id[] , int P[maxn][logn]){
P[u][0] = par;
for(int i = 1 ; i < logn ; ++i){
if(P[u][i - 1] >= 0 && P[u][i - 1] < n)P[u][i] = P[P[u][i - 1]][i - 1];
else P[u][i] = P[u][i - 1];
}
in[u] = ++nTime;
id[nTime] = u;
for(int c : adj[u]){
DFS(c , u , adj , in , out, id , P);
}
out[u] = nTime;
}
int bit[maxn];
void add(int x){
for(;x <= n ;x += x & -x){
bit[x]++;
}
}
int query(int x){
int res = 0;
for( ; x > 0 ; x &= x - 1){
res += bit[x];
}
return res;
}
vector<tuple<int,int,int,int>> a[maxn];
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){
e[X[i]].pb(Y[i]);
e[Y[i]].pb(X[i]);
}
fill_n(lab,maxn,-1);
function<int(int)> FindLab = [&](int u){
return lab[u] < 0 ? u : lab[u] = FindLab(lab[u]);
};
auto add = [&](int x , int y , vector<int> adj[]){
int s = FindLab(x);
int d = FindLab(y);
if(s == d)return;
lab[d] = s;
adj[s].pb(d);
};
for(int i = 0 ; i < n ; ++i){
for(int c : e[i]){
if(c < i)add(i , c , radj);
}
}
fill_n(lab,maxn,-1);
for(int i = n - 1 ; i >= 0 ; --i){
for(int c : e[i]){
if(c > i)add(i , c , adj);
}
}
DFS(0 , -1 , adj , in[0] , out[0] , id[0] , P[0]);
nTime = 0;
DFS(n - 1 , n , radj , in[1] , out[1] , id[1] , P[1]);
int q = S.size();
vector<int> res(q , 0);
for(int i = 0 ; i < q ; ++i){
int s = S[i];int e = E[i];
for(int j = logn - 1 ; j >= 0 ; --j){
if(P[0][s][j] >= L[i])s = P[0][s][j];
if(P[1][e][j] <= R[i])e = P[1][e][j];
}
a[in[0][s] - 1].emplace_back(-1 , in[1][e] , out[1][e] , i);
a[out[0][s]].emplace_back(1 , in[1][e] , out[1][e] , i);
}
for(int i = 1 ; i <= n ; ++i){
::add(in[1][id[0][i]]);
// cout << in[1][id[0][i]] << endl;
for(auto & c : a[i]){
int delta , l , r , id;
tie(delta , l , r , id) = c;
res[id] += delta * (query(r) - query(l - 1));
}
}
for(int i = 0 ; i < q ; ++i){
res[i] = res[i] > 0;
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
19960 KB |
Output is correct |
2 |
Correct |
21 ms |
19960 KB |
Output is correct |
3 |
Correct |
24 ms |
19960 KB |
Output is correct |
4 |
Correct |
21 ms |
19964 KB |
Output is correct |
5 |
Correct |
21 ms |
19960 KB |
Output is correct |
6 |
Correct |
22 ms |
19960 KB |
Output is correct |
7 |
Correct |
25 ms |
19976 KB |
Output is correct |
8 |
Correct |
20 ms |
19960 KB |
Output is correct |
9 |
Correct |
26 ms |
19960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
19960 KB |
Output is correct |
2 |
Correct |
21 ms |
19960 KB |
Output is correct |
3 |
Correct |
24 ms |
19960 KB |
Output is correct |
4 |
Correct |
21 ms |
19964 KB |
Output is correct |
5 |
Correct |
21 ms |
19960 KB |
Output is correct |
6 |
Correct |
22 ms |
19960 KB |
Output is correct |
7 |
Correct |
25 ms |
19976 KB |
Output is correct |
8 |
Correct |
20 ms |
19960 KB |
Output is correct |
9 |
Correct |
26 ms |
19960 KB |
Output is correct |
10 |
Correct |
28 ms |
21112 KB |
Output is correct |
11 |
Correct |
27 ms |
21136 KB |
Output is correct |
12 |
Correct |
26 ms |
21088 KB |
Output is correct |
13 |
Correct |
32 ms |
21368 KB |
Output is correct |
14 |
Correct |
27 ms |
21368 KB |
Output is correct |
15 |
Correct |
28 ms |
21240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
769 ms |
88136 KB |
Output is correct |
2 |
Correct |
706 ms |
96024 KB |
Output is correct |
3 |
Correct |
615 ms |
89976 KB |
Output is correct |
4 |
Correct |
744 ms |
86960 KB |
Output is correct |
5 |
Correct |
634 ms |
87060 KB |
Output is correct |
6 |
Correct |
685 ms |
88156 KB |
Output is correct |
7 |
Correct |
637 ms |
86320 KB |
Output is correct |
8 |
Correct |
654 ms |
95856 KB |
Output is correct |
9 |
Correct |
580 ms |
88908 KB |
Output is correct |
10 |
Correct |
559 ms |
86716 KB |
Output is correct |
11 |
Correct |
544 ms |
86348 KB |
Output is correct |
12 |
Correct |
550 ms |
85968 KB |
Output is correct |
13 |
Correct |
796 ms |
102048 KB |
Output is correct |
14 |
Correct |
923 ms |
101924 KB |
Output is correct |
15 |
Correct |
951 ms |
101976 KB |
Output is correct |
16 |
Correct |
999 ms |
101960 KB |
Output is correct |
17 |
Correct |
683 ms |
86520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
19960 KB |
Output is correct |
2 |
Correct |
21 ms |
19960 KB |
Output is correct |
3 |
Correct |
24 ms |
19960 KB |
Output is correct |
4 |
Correct |
21 ms |
19964 KB |
Output is correct |
5 |
Correct |
21 ms |
19960 KB |
Output is correct |
6 |
Correct |
22 ms |
19960 KB |
Output is correct |
7 |
Correct |
25 ms |
19976 KB |
Output is correct |
8 |
Correct |
20 ms |
19960 KB |
Output is correct |
9 |
Correct |
26 ms |
19960 KB |
Output is correct |
10 |
Correct |
28 ms |
21112 KB |
Output is correct |
11 |
Correct |
27 ms |
21136 KB |
Output is correct |
12 |
Correct |
26 ms |
21088 KB |
Output is correct |
13 |
Correct |
32 ms |
21368 KB |
Output is correct |
14 |
Correct |
27 ms |
21368 KB |
Output is correct |
15 |
Correct |
28 ms |
21240 KB |
Output is correct |
16 |
Correct |
769 ms |
88136 KB |
Output is correct |
17 |
Correct |
706 ms |
96024 KB |
Output is correct |
18 |
Correct |
615 ms |
89976 KB |
Output is correct |
19 |
Correct |
744 ms |
86960 KB |
Output is correct |
20 |
Correct |
634 ms |
87060 KB |
Output is correct |
21 |
Correct |
685 ms |
88156 KB |
Output is correct |
22 |
Correct |
637 ms |
86320 KB |
Output is correct |
23 |
Correct |
654 ms |
95856 KB |
Output is correct |
24 |
Correct |
580 ms |
88908 KB |
Output is correct |
25 |
Correct |
559 ms |
86716 KB |
Output is correct |
26 |
Correct |
544 ms |
86348 KB |
Output is correct |
27 |
Correct |
550 ms |
85968 KB |
Output is correct |
28 |
Correct |
796 ms |
102048 KB |
Output is correct |
29 |
Correct |
923 ms |
101924 KB |
Output is correct |
30 |
Correct |
951 ms |
101976 KB |
Output is correct |
31 |
Correct |
999 ms |
101960 KB |
Output is correct |
32 |
Correct |
683 ms |
86520 KB |
Output is correct |
33 |
Correct |
809 ms |
90000 KB |
Output is correct |
34 |
Correct |
384 ms |
47456 KB |
Output is correct |
35 |
Correct |
843 ms |
94968 KB |
Output is correct |
36 |
Correct |
823 ms |
89592 KB |
Output is correct |
37 |
Correct |
858 ms |
93624 KB |
Output is correct |
38 |
Correct |
817 ms |
90780 KB |
Output is correct |
39 |
Correct |
880 ms |
111608 KB |
Output is correct |
40 |
Correct |
925 ms |
96780 KB |
Output is correct |
41 |
Correct |
732 ms |
91252 KB |
Output is correct |
42 |
Correct |
579 ms |
87136 KB |
Output is correct |
43 |
Correct |
886 ms |
100704 KB |
Output is correct |
44 |
Correct |
739 ms |
93304 KB |
Output is correct |
45 |
Correct |
662 ms |
110072 KB |
Output is correct |
46 |
Correct |
670 ms |
110576 KB |
Output is correct |
47 |
Correct |
767 ms |
102048 KB |
Output is correct |
48 |
Correct |
748 ms |
102152 KB |
Output is correct |
49 |
Correct |
764 ms |
101988 KB |
Output is correct |
50 |
Correct |
837 ms |
101976 KB |
Output is correct |
51 |
Correct |
888 ms |
96980 KB |
Output is correct |
52 |
Correct |
915 ms |
96932 KB |
Output is correct |