#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 2e5 + 5, lg = 19;
int n, q;
vector<int> edge[Nmax];
int node_A[Nmax], node_B[Nmax];
vector<pair<int,int>> when[Nmax];
struct Arb
{
vector<int> son[Nmax];
int L[Nmax], R[Nmax], tmp = 0;
int root;
int up[lg+2][Nmax];
void dfs(int node, int dad = -1)
{
L[node] = ++tmp;
up[0][node] = dad;
int i;
for(i=1; up[i-1][node] != -1; ++i)
up[i][node] = up[i-1][up[i-1][node]];
for(; i<=lg; ++i) up[i][node] = -1;
for(auto it : son[node])
dfs(it, node);
R[node] = tmp;
}
} A, B;
struct Forest
{
int t[Nmax];
int boss(int x)
{
if(x == t[x]) return x;
return t[x] = boss(t[x]);
}
void init()
{
int i;
for(i=0; i<n; ++i) t[i] = i;
}
bool unite(int x, int y)
{
if(x == y) return 0;
t[y] = x;
return 1;
}
} forest;
auto MinSort = [] (int x, int y) { return x < y; };
auto MaxSort = [] (int x, int y) { return x > y; };
void build_tree(Arb &A, function<bool(int, int)> cmp)
{
vector<int> ord;
int i;
for(i=0; i<n; ++i) ord.push_back(i);
sort(ord.begin(), ord.end(), cmp);
forest.init();
for(auto node : ord)
for(auto it : edge[node])
if(cmp(it, node))
{
int who = forest.boss(it);
if(who == node) continue;
A.son[node].push_back(who);
forest.t[who] = node;
}
A.root = ord.back();
A.dfs(A.root);
}
int fnd(Arb &A, int node, int lim, function<bool (int, int)> cmp)
{
int i;
for(i=lg; i>=0; --i)
if(A.up[i][node] != -1 && cmp(A.up[i][node], lim)) node = A.up[i][node];
return node;
}
void find_queries(vector<int> &S, vector<int> &E, vector<int> &L, vector<int> &R)
{
int i;
for(i=0; i<q; ++i)
{
node_A[i] = fnd(A, S[i], L[i] - 1, MaxSort);
node_B[i] = fnd(B, E[i], R[i] + 1, MinSort);
}
}
set<int> s[Nmax];
int w[Nmax];
vector<int> ans;
void dfs(int node)
{
w[node] = 1;
for(auto it : A.son[node])
{
dfs(it);
w[node] += w[it];
}
int xson = -1;
for(auto it : A.son[node])
if(xson == -1 || w[it] > w[xson]) xson = it;
if(xson != -1) swap(s[node], s[xson]);
for(auto it : A.son[node])
if(it != xson)
for(auto x : s[it])
s[node].insert(x);
s[node].insert(B.L[node]);
for(auto it : when[node])
{
int bnode, id;
tie(bnode, id) = it;
set<int> :: iterator itt = s[node].lower_bound(B.L[bnode]);
if(itt != s[node].end() && *itt <= B.R[bnode])
ans[id] = 1;
else ans[id] = 0;
}
}
void solve_queries()
{
int i;
for(i=0; i<q; ++i)
when[node_A[i]].push_back({ node_B[i], i });
dfs(A.root);
}
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;
q = S.size();
ans.resize(q);
int i;
for(i=0; i<X.size(); ++i)
{
edge[X[i]].push_back(Y[i]);
edge[Y[i]].push_back(X[i]);
}
build_tree(A, MaxSort);
build_tree(B, MinSort);
find_queries(S, E, L, R);
solve_queries();
return ans;
}
Compilation message
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:165:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0; i<X.size(); ++i)
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
28792 KB |
Output is correct |
2 |
Correct |
27 ms |
28792 KB |
Output is correct |
3 |
Correct |
26 ms |
28800 KB |
Output is correct |
4 |
Correct |
26 ms |
28800 KB |
Output is correct |
5 |
Correct |
27 ms |
28920 KB |
Output is correct |
6 |
Correct |
25 ms |
28800 KB |
Output is correct |
7 |
Correct |
26 ms |
28792 KB |
Output is correct |
8 |
Correct |
26 ms |
28772 KB |
Output is correct |
9 |
Correct |
26 ms |
28800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
28792 KB |
Output is correct |
2 |
Correct |
27 ms |
28792 KB |
Output is correct |
3 |
Correct |
26 ms |
28800 KB |
Output is correct |
4 |
Correct |
26 ms |
28800 KB |
Output is correct |
5 |
Correct |
27 ms |
28920 KB |
Output is correct |
6 |
Correct |
25 ms |
28800 KB |
Output is correct |
7 |
Correct |
26 ms |
28792 KB |
Output is correct |
8 |
Correct |
26 ms |
28772 KB |
Output is correct |
9 |
Correct |
26 ms |
28800 KB |
Output is correct |
10 |
Correct |
36 ms |
30180 KB |
Output is correct |
11 |
Correct |
35 ms |
30328 KB |
Output is correct |
12 |
Correct |
35 ms |
30372 KB |
Output is correct |
13 |
Correct |
36 ms |
30328 KB |
Output is correct |
14 |
Correct |
35 ms |
30456 KB |
Output is correct |
15 |
Correct |
36 ms |
30328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1276 ms |
154884 KB |
Output is correct |
2 |
Correct |
1303 ms |
128004 KB |
Output is correct |
3 |
Correct |
1149 ms |
137304 KB |
Output is correct |
4 |
Correct |
1117 ms |
152024 KB |
Output is correct |
5 |
Correct |
1126 ms |
155208 KB |
Output is correct |
6 |
Correct |
1188 ms |
160600 KB |
Output is correct |
7 |
Correct |
1314 ms |
163288 KB |
Output is correct |
8 |
Correct |
1194 ms |
127816 KB |
Output is correct |
9 |
Correct |
792 ms |
136920 KB |
Output is correct |
10 |
Correct |
827 ms |
151780 KB |
Output is correct |
11 |
Correct |
903 ms |
153048 KB |
Output is correct |
12 |
Correct |
992 ms |
159164 KB |
Output is correct |
13 |
Correct |
1252 ms |
132884 KB |
Output is correct |
14 |
Correct |
1295 ms |
132824 KB |
Output is correct |
15 |
Correct |
1323 ms |
133056 KB |
Output is correct |
16 |
Correct |
1296 ms |
133064 KB |
Output is correct |
17 |
Correct |
1236 ms |
161368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
28792 KB |
Output is correct |
2 |
Correct |
27 ms |
28792 KB |
Output is correct |
3 |
Correct |
26 ms |
28800 KB |
Output is correct |
4 |
Correct |
26 ms |
28800 KB |
Output is correct |
5 |
Correct |
27 ms |
28920 KB |
Output is correct |
6 |
Correct |
25 ms |
28800 KB |
Output is correct |
7 |
Correct |
26 ms |
28792 KB |
Output is correct |
8 |
Correct |
26 ms |
28772 KB |
Output is correct |
9 |
Correct |
26 ms |
28800 KB |
Output is correct |
10 |
Correct |
36 ms |
30180 KB |
Output is correct |
11 |
Correct |
35 ms |
30328 KB |
Output is correct |
12 |
Correct |
35 ms |
30372 KB |
Output is correct |
13 |
Correct |
36 ms |
30328 KB |
Output is correct |
14 |
Correct |
35 ms |
30456 KB |
Output is correct |
15 |
Correct |
36 ms |
30328 KB |
Output is correct |
16 |
Correct |
1276 ms |
154884 KB |
Output is correct |
17 |
Correct |
1303 ms |
128004 KB |
Output is correct |
18 |
Correct |
1149 ms |
137304 KB |
Output is correct |
19 |
Correct |
1117 ms |
152024 KB |
Output is correct |
20 |
Correct |
1126 ms |
155208 KB |
Output is correct |
21 |
Correct |
1188 ms |
160600 KB |
Output is correct |
22 |
Correct |
1314 ms |
163288 KB |
Output is correct |
23 |
Correct |
1194 ms |
127816 KB |
Output is correct |
24 |
Correct |
792 ms |
136920 KB |
Output is correct |
25 |
Correct |
827 ms |
151780 KB |
Output is correct |
26 |
Correct |
903 ms |
153048 KB |
Output is correct |
27 |
Correct |
992 ms |
159164 KB |
Output is correct |
28 |
Correct |
1252 ms |
132884 KB |
Output is correct |
29 |
Correct |
1295 ms |
132824 KB |
Output is correct |
30 |
Correct |
1323 ms |
133056 KB |
Output is correct |
31 |
Correct |
1296 ms |
133064 KB |
Output is correct |
32 |
Correct |
1236 ms |
161368 KB |
Output is correct |
33 |
Correct |
1321 ms |
131872 KB |
Output is correct |
34 |
Correct |
361 ms |
64636 KB |
Output is correct |
35 |
Correct |
1513 ms |
129496 KB |
Output is correct |
36 |
Correct |
1316 ms |
135268 KB |
Output is correct |
37 |
Correct |
1318 ms |
129032 KB |
Output is correct |
38 |
Correct |
1448 ms |
133720 KB |
Output is correct |
39 |
Correct |
1334 ms |
146188 KB |
Output is correct |
40 |
Correct |
1425 ms |
136912 KB |
Output is correct |
41 |
Correct |
1210 ms |
127796 KB |
Output is correct |
42 |
Correct |
1002 ms |
133960 KB |
Output is correct |
43 |
Correct |
1315 ms |
134744 KB |
Output is correct |
44 |
Correct |
1133 ms |
128188 KB |
Output is correct |
45 |
Correct |
1163 ms |
137396 KB |
Output is correct |
46 |
Correct |
1240 ms |
145752 KB |
Output is correct |
47 |
Correct |
1305 ms |
133180 KB |
Output is correct |
48 |
Correct |
1285 ms |
133036 KB |
Output is correct |
49 |
Correct |
1276 ms |
133028 KB |
Output is correct |
50 |
Correct |
1310 ms |
133000 KB |
Output is correct |
51 |
Correct |
1251 ms |
136196 KB |
Output is correct |
52 |
Correct |
1258 ms |
136108 KB |
Output is correct |