#pragma GCC optimize("O3")
#pragma GCC target("popcnt")
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5;
const int BLOCK = 150;
const int LOGMAX = 18;
struct order{
vector<int> v;
bitset<MAX> st[MAX / BLOCK + 2];
void preCalc(){
int p = 0;
for (int i = 0; i < v.size(); i++)
{
if(i % BLOCK == 0){
p++;
st[p] = st[p - 1];
}
st[p][v[i]] = 1;
}
}
bitset<MAX> query(int p){
bitset<MAX> ans = st[p / BLOCK];
for (int i = p / BLOCK * BLOCK; i <= p; i++)
{
ans[v[i]] = 1;
}
return ans;
}
};
int n;
struct graph{
vector<int> tree[MAX];
int par[LOGMAX][MAX];
order v;
int timeIn[MAX], timeOut[MAX];
void dfs(int node, int p){
par[0][node] = p;
timeIn[node] = v.v.size();
v.v.push_back(node);
for(int to:tree[node]){
if(to == p) continue;
dfs(to, node);
}
timeOut[node] = v.v.size() - 1;
}
void preCalc(){
for (int j = 1; j < LOGMAX; j++)
{
for (int i = 0; i < n; i++)
{
par[j][i] = par[j - 1][par[j - 1][i]];
}
}
v.preCalc();
}
int lift1(int v, int a){
for(int j = LOGMAX - 1; j >= 0; --j){
int u = par[j][v];
if(u >= a){
v = u;
}
}
return v;
}
int lift2(int v, int a){
for(int j = LOGMAX - 1; j >= 0; --j){
int u = par[j][v];
if(u <= a){
v = u;
}
}
return v;
}
bitset<MAX> ask(int node){
return v.query(timeOut[node]) ^ v.query(timeIn[node] - 1);
}
};
vector<int> g[MAX];
graph tree1, tree2;
struct DSU{
int par[MAX];
bool b = 0;
void init(int N, bool _b){
b = _b;
memset(par, -1, sizeof(par));
}
int get(int node){
if(par[node] < 0) return node;
return par[node] = get(par[node]);
}
bool unite(int v, int u){
v = get(v);
u = get(u);
if(v == u) return false;
if(v < u && b) swap(v, u);
if(v > u && !b) swap(v, u);
par[v] += par[u];
par[u] = v;
return true;
}
};
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;
DSU dsu;
for (int i = 0; i < X.size(); i++)
{
g[X[i]].push_back(Y[i]);
g[Y[i]].push_back(X[i]);
}
dsu.init(N, 0);
for (int node = N - 1; node >= 0; node--)
{
for(int to:g[node]){
if(to < node) continue;
int a = dsu.get(to);
if(dsu.unite(node, to)){
tree1.tree[node].push_back(a);
}
}
}
dsu.init(N, 1);
for (int node = 0; node < N; node++)
{
for(int to:g[node]){
if(to > node) continue;
int a = dsu.get(to);
if(dsu.unite(node, to)){
tree2.tree[node].push_back(a);
}
}
}
tree1.dfs(0, 0);
tree2.dfs(n - 1, n - 1);
tree1.preCalc();
tree2.preCalc();
vector<int> ans(S.size());
for (int i = 0; i < S.size(); i++)
{
int a = tree1.lift1(S[i], L[i]);
int b = tree2.lift2(E[i], R[i]);
ans[i] = (tree1.ask(a) & tree2.ask(b)).any();
}
return ans;
}
Compilation message
werewolf.cpp: In member function 'void order::preCalc()':
werewolf.cpp:18:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:116:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
116 | for (int i = 0; i < X.size(); i++)
| ~~^~~~~~~~~~
werewolf.cpp:149:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
149 | for (int i = 0; i < S.size(); i++)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
80772 KB |
Output is correct |
2 |
Correct |
33 ms |
80772 KB |
Output is correct |
3 |
Correct |
32 ms |
80724 KB |
Output is correct |
4 |
Correct |
41 ms |
80784 KB |
Output is correct |
5 |
Correct |
32 ms |
80808 KB |
Output is correct |
6 |
Correct |
31 ms |
80760 KB |
Output is correct |
7 |
Correct |
30 ms |
80852 KB |
Output is correct |
8 |
Correct |
31 ms |
80744 KB |
Output is correct |
9 |
Correct |
31 ms |
80736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
80772 KB |
Output is correct |
2 |
Correct |
33 ms |
80772 KB |
Output is correct |
3 |
Correct |
32 ms |
80724 KB |
Output is correct |
4 |
Correct |
41 ms |
80784 KB |
Output is correct |
5 |
Correct |
32 ms |
80808 KB |
Output is correct |
6 |
Correct |
31 ms |
80760 KB |
Output is correct |
7 |
Correct |
30 ms |
80852 KB |
Output is correct |
8 |
Correct |
31 ms |
80744 KB |
Output is correct |
9 |
Correct |
31 ms |
80736 KB |
Output is correct |
10 |
Correct |
64 ms |
81832 KB |
Output is correct |
11 |
Correct |
53 ms |
81812 KB |
Output is correct |
12 |
Correct |
53 ms |
81796 KB |
Output is correct |
13 |
Correct |
53 ms |
81896 KB |
Output is correct |
14 |
Correct |
52 ms |
81820 KB |
Output is correct |
15 |
Correct |
58 ms |
81932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3071 ms |
139452 KB |
Output is correct |
2 |
Correct |
3088 ms |
142044 KB |
Output is correct |
3 |
Correct |
3014 ms |
140484 KB |
Output is correct |
4 |
Correct |
2641 ms |
139720 KB |
Output is correct |
5 |
Correct |
2765 ms |
139692 KB |
Output is correct |
6 |
Correct |
2986 ms |
139740 KB |
Output is correct |
7 |
Correct |
2449 ms |
139700 KB |
Output is correct |
8 |
Correct |
3203 ms |
142176 KB |
Output is correct |
9 |
Correct |
2348 ms |
140604 KB |
Output is correct |
10 |
Correct |
1714 ms |
140048 KB |
Output is correct |
11 |
Correct |
1744 ms |
140064 KB |
Output is correct |
12 |
Correct |
1887 ms |
139108 KB |
Output is correct |
13 |
Correct |
2945 ms |
146268 KB |
Output is correct |
14 |
Correct |
2781 ms |
146244 KB |
Output is correct |
15 |
Correct |
2908 ms |
146252 KB |
Output is correct |
16 |
Correct |
2886 ms |
146132 KB |
Output is correct |
17 |
Correct |
2430 ms |
138808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
80772 KB |
Output is correct |
2 |
Correct |
33 ms |
80772 KB |
Output is correct |
3 |
Correct |
32 ms |
80724 KB |
Output is correct |
4 |
Correct |
41 ms |
80784 KB |
Output is correct |
5 |
Correct |
32 ms |
80808 KB |
Output is correct |
6 |
Correct |
31 ms |
80760 KB |
Output is correct |
7 |
Correct |
30 ms |
80852 KB |
Output is correct |
8 |
Correct |
31 ms |
80744 KB |
Output is correct |
9 |
Correct |
31 ms |
80736 KB |
Output is correct |
10 |
Correct |
64 ms |
81832 KB |
Output is correct |
11 |
Correct |
53 ms |
81812 KB |
Output is correct |
12 |
Correct |
53 ms |
81796 KB |
Output is correct |
13 |
Correct |
53 ms |
81896 KB |
Output is correct |
14 |
Correct |
52 ms |
81820 KB |
Output is correct |
15 |
Correct |
58 ms |
81932 KB |
Output is correct |
16 |
Correct |
3071 ms |
139452 KB |
Output is correct |
17 |
Correct |
3088 ms |
142044 KB |
Output is correct |
18 |
Correct |
3014 ms |
140484 KB |
Output is correct |
19 |
Correct |
2641 ms |
139720 KB |
Output is correct |
20 |
Correct |
2765 ms |
139692 KB |
Output is correct |
21 |
Correct |
2986 ms |
139740 KB |
Output is correct |
22 |
Correct |
2449 ms |
139700 KB |
Output is correct |
23 |
Correct |
3203 ms |
142176 KB |
Output is correct |
24 |
Correct |
2348 ms |
140604 KB |
Output is correct |
25 |
Correct |
1714 ms |
140048 KB |
Output is correct |
26 |
Correct |
1744 ms |
140064 KB |
Output is correct |
27 |
Correct |
1887 ms |
139108 KB |
Output is correct |
28 |
Correct |
2945 ms |
146268 KB |
Output is correct |
29 |
Correct |
2781 ms |
146244 KB |
Output is correct |
30 |
Correct |
2908 ms |
146252 KB |
Output is correct |
31 |
Correct |
2886 ms |
146132 KB |
Output is correct |
32 |
Correct |
2430 ms |
138808 KB |
Output is correct |
33 |
Correct |
3269 ms |
139012 KB |
Output is correct |
34 |
Correct |
1517 ms |
101216 KB |
Output is correct |
35 |
Correct |
3422 ms |
140732 KB |
Output is correct |
36 |
Correct |
3377 ms |
144824 KB |
Output is correct |
37 |
Correct |
3289 ms |
145912 KB |
Output is correct |
38 |
Correct |
3392 ms |
145188 KB |
Output is correct |
39 |
Correct |
2838 ms |
151984 KB |
Output is correct |
40 |
Correct |
2545 ms |
148660 KB |
Output is correct |
41 |
Correct |
2533 ms |
146732 KB |
Output is correct |
42 |
Correct |
1761 ms |
146076 KB |
Output is correct |
43 |
Correct |
3093 ms |
149724 KB |
Output is correct |
44 |
Correct |
3314 ms |
141280 KB |
Output is correct |
45 |
Correct |
2137 ms |
147468 KB |
Output is correct |
46 |
Correct |
2419 ms |
147380 KB |
Output is correct |
47 |
Correct |
2962 ms |
147104 KB |
Output is correct |
48 |
Correct |
2867 ms |
147024 KB |
Output is correct |
49 |
Correct |
2859 ms |
146084 KB |
Output is correct |
50 |
Correct |
2887 ms |
145700 KB |
Output is correct |
51 |
Correct |
1883 ms |
145364 KB |
Output is correct |
52 |
Correct |
1813 ms |
145292 KB |
Output is correct |