#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 : 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 |
10 ms |
19908 KB |
Output is correct |
2 |
Correct |
10 ms |
19848 KB |
Output is correct |
3 |
Correct |
10 ms |
19852 KB |
Output is correct |
4 |
Correct |
11 ms |
19840 KB |
Output is correct |
5 |
Correct |
11 ms |
19916 KB |
Output is correct |
6 |
Correct |
10 ms |
19908 KB |
Output is correct |
7 |
Correct |
10 ms |
19916 KB |
Output is correct |
8 |
Correct |
10 ms |
19916 KB |
Output is correct |
9 |
Correct |
10 ms |
19968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19908 KB |
Output is correct |
2 |
Correct |
10 ms |
19848 KB |
Output is correct |
3 |
Correct |
10 ms |
19852 KB |
Output is correct |
4 |
Correct |
11 ms |
19840 KB |
Output is correct |
5 |
Correct |
11 ms |
19916 KB |
Output is correct |
6 |
Correct |
10 ms |
19908 KB |
Output is correct |
7 |
Correct |
10 ms |
19916 KB |
Output is correct |
8 |
Correct |
10 ms |
19916 KB |
Output is correct |
9 |
Correct |
10 ms |
19968 KB |
Output is correct |
10 |
Correct |
20 ms |
21124 KB |
Output is correct |
11 |
Correct |
15 ms |
21028 KB |
Output is correct |
12 |
Correct |
14 ms |
21068 KB |
Output is correct |
13 |
Correct |
28 ms |
21316 KB |
Output is correct |
14 |
Correct |
26 ms |
21368 KB |
Output is correct |
15 |
Correct |
27 ms |
21104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
524 ms |
96420 KB |
Output is correct |
2 |
Correct |
506 ms |
104128 KB |
Output is correct |
3 |
Correct |
422 ms |
98164 KB |
Output is correct |
4 |
Correct |
420 ms |
95120 KB |
Output is correct |
5 |
Correct |
429 ms |
95112 KB |
Output is correct |
6 |
Correct |
480 ms |
96276 KB |
Output is correct |
7 |
Correct |
464 ms |
94608 KB |
Output is correct |
8 |
Correct |
482 ms |
104032 KB |
Output is correct |
9 |
Correct |
374 ms |
97060 KB |
Output is correct |
10 |
Correct |
329 ms |
94844 KB |
Output is correct |
11 |
Correct |
349 ms |
94476 KB |
Output is correct |
12 |
Correct |
380 ms |
94132 KB |
Output is correct |
13 |
Correct |
584 ms |
110052 KB |
Output is correct |
14 |
Correct |
554 ms |
109972 KB |
Output is correct |
15 |
Correct |
561 ms |
110004 KB |
Output is correct |
16 |
Correct |
545 ms |
110064 KB |
Output is correct |
17 |
Correct |
467 ms |
94736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19908 KB |
Output is correct |
2 |
Correct |
10 ms |
19848 KB |
Output is correct |
3 |
Correct |
10 ms |
19852 KB |
Output is correct |
4 |
Correct |
11 ms |
19840 KB |
Output is correct |
5 |
Correct |
11 ms |
19916 KB |
Output is correct |
6 |
Correct |
10 ms |
19908 KB |
Output is correct |
7 |
Correct |
10 ms |
19916 KB |
Output is correct |
8 |
Correct |
10 ms |
19916 KB |
Output is correct |
9 |
Correct |
10 ms |
19968 KB |
Output is correct |
10 |
Correct |
20 ms |
21124 KB |
Output is correct |
11 |
Correct |
15 ms |
21028 KB |
Output is correct |
12 |
Correct |
14 ms |
21068 KB |
Output is correct |
13 |
Correct |
28 ms |
21316 KB |
Output is correct |
14 |
Correct |
26 ms |
21368 KB |
Output is correct |
15 |
Correct |
27 ms |
21104 KB |
Output is correct |
16 |
Correct |
524 ms |
96420 KB |
Output is correct |
17 |
Correct |
506 ms |
104128 KB |
Output is correct |
18 |
Correct |
422 ms |
98164 KB |
Output is correct |
19 |
Correct |
420 ms |
95120 KB |
Output is correct |
20 |
Correct |
429 ms |
95112 KB |
Output is correct |
21 |
Correct |
480 ms |
96276 KB |
Output is correct |
22 |
Correct |
464 ms |
94608 KB |
Output is correct |
23 |
Correct |
482 ms |
104032 KB |
Output is correct |
24 |
Correct |
374 ms |
97060 KB |
Output is correct |
25 |
Correct |
329 ms |
94844 KB |
Output is correct |
26 |
Correct |
349 ms |
94476 KB |
Output is correct |
27 |
Correct |
380 ms |
94132 KB |
Output is correct |
28 |
Correct |
584 ms |
110052 KB |
Output is correct |
29 |
Correct |
554 ms |
109972 KB |
Output is correct |
30 |
Correct |
561 ms |
110004 KB |
Output is correct |
31 |
Correct |
545 ms |
110064 KB |
Output is correct |
32 |
Correct |
467 ms |
94736 KB |
Output is correct |
33 |
Correct |
1421 ms |
98004 KB |
Output is correct |
34 |
Correct |
2400 ms |
58940 KB |
Output is correct |
35 |
Execution timed out |
4046 ms |
49536 KB |
Time limit exceeded |
36 |
Halted |
0 ms |
0 KB |
- |