#include "werewolf.h"
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int,int> pi;
typedef vector <int> vec;
const int INF = 1e9;
int n,m,Q,uni[200005];
vector <int> v[200005],tvn[200005],tv1[200005];
int p1[200005][18],pn[200005][18];
int in1[200005],inn[200005],out1[200005],outn[200005],co;
int bu[200005];
vector <int> t[800005];
int Find(int x) {return (x == uni[x] ? x : uni[x] = Find(uni[x]));}
void dfs_mark1(int x) {
in1[x] = ++co;
for(int i : tv1[x]) dfs_mark1(i);
out1[x] = co;
}
void dfs_markn(int x) {
inn[x] = ++co;
for(int i : tvn[x]) dfs_markn(i);
outn[x] = co;
}
void build(int x,int l,int r) {
if(l == r) {
t[x].push_back(bu[l]);
return;
}
int mid = (l + r) >> 1;
build(x*2,l,mid), build(x*2+1,mid+1,r);
for(int i : t[x*2]) t[x].push_back(i);
for(int i : t[x*2+1]) t[x].push_back(i);
sort(t[x].begin(),t[x].end());
}
int query(int x,int l,int r,int rl,int rr,int ql,int qr) {
if(rl <= l&&r <= rr) {
int it1 = upper_bound(t[x].begin(),t[x].end(),qr)-t[x].begin()-1, it2 = lower_bound(t[x].begin(),t[x].end(),ql)-t[x].begin()-1;
return (it1-it2 > 0);
}
if(rl > r||l > rr) return 0;
int mid = (l + r) >> 1;
return (query(x*2,l,mid,rl,rr,ql,qr)||query(x*2+1,mid+1,r,rl,rr,ql,qr));
}
vec check_validity(int N,vec X,vec Y,vec S,vec E,vec L,vec R) {
n = N, m = X.size(), Q = S.size();
for(int i = 0;i < m;i++) {
X[i]++, Y[i]++;
v[X[i]].push_back(Y[i]);
v[Y[i]].push_back(X[i]);
}
for(int i = 0;i < Q;i++) {
S[i]++, E[i]++, L[i]++, R[i]++;
}
pn[n][0] = n, p1[1][0] = 1;
for(int i = 1;i <= n;i++) uni[i] = i;
for(int i = 1;i <= n;i++) {
for(int j : v[i]) {
if(j < i) {
if(Find(j) != i) {
int tmp = Find(j); uni[tmp] = i;
pn[tmp][0] = i, tvn[i].push_back(tmp);
}
}
}
}
for(int i = 1;i <= n;i++) uni[i] = i;
for(int i = n;i >= 1;i--) {
for(int j : v[i]) {
if(j > i) {
if(Find(j) != i) {
int tmp = Find(j); uni[tmp] = i;
p1[tmp][0] = i, tv1[i].push_back(tmp);
}
}
}
}
for(int i = 1;i < 18;i++) {
for(int j = 1;j <= n;j++) {
pn[j][i] = pn[pn[j][i-1]][i-1];
p1[j][i] = p1[p1[j][i-1]][i-1];
}
}
dfs_mark1(1); co = 0;
dfs_markn(n);
for(int i = 1;i <= n;i++) bu[inn[i]] = in1[i];
build(1,1,n);
vec ans;
for(int i = 0;i < Q;i++) {
int l,r,x = E[i],l2,r2;
for(int j = 17;j >= 0;j--) {
if(pn[x][j] <= R[i]) x = pn[x][j];
}
l = inn[x], r = outn[x]; x = S[i];
for(int j = 17;j >= 0;j--) {
if(p1[x][j] >= L[i]) x = p1[x][j];
}
l2 = in1[x], r2 = out1[x];
ans.push_back(query(1,1,n,l,r,l2,r2));
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
33204 KB |
Output is correct |
2 |
Correct |
17 ms |
33228 KB |
Output is correct |
3 |
Correct |
19 ms |
33204 KB |
Output is correct |
4 |
Correct |
20 ms |
33236 KB |
Output is correct |
5 |
Correct |
16 ms |
33204 KB |
Output is correct |
6 |
Correct |
17 ms |
33236 KB |
Output is correct |
7 |
Correct |
16 ms |
33236 KB |
Output is correct |
8 |
Correct |
18 ms |
33236 KB |
Output is correct |
9 |
Correct |
17 ms |
33156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
33204 KB |
Output is correct |
2 |
Correct |
17 ms |
33228 KB |
Output is correct |
3 |
Correct |
19 ms |
33204 KB |
Output is correct |
4 |
Correct |
20 ms |
33236 KB |
Output is correct |
5 |
Correct |
16 ms |
33204 KB |
Output is correct |
6 |
Correct |
17 ms |
33236 KB |
Output is correct |
7 |
Correct |
16 ms |
33236 KB |
Output is correct |
8 |
Correct |
18 ms |
33236 KB |
Output is correct |
9 |
Correct |
17 ms |
33156 KB |
Output is correct |
10 |
Correct |
23 ms |
34548 KB |
Output is correct |
11 |
Correct |
23 ms |
34496 KB |
Output is correct |
12 |
Correct |
21 ms |
34568 KB |
Output is correct |
13 |
Correct |
27 ms |
34644 KB |
Output is correct |
14 |
Correct |
24 ms |
34640 KB |
Output is correct |
15 |
Correct |
25 ms |
34664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
831 ms |
126960 KB |
Output is correct |
2 |
Correct |
753 ms |
128828 KB |
Output is correct |
3 |
Correct |
745 ms |
127528 KB |
Output is correct |
4 |
Correct |
862 ms |
127100 KB |
Output is correct |
5 |
Correct |
904 ms |
127084 KB |
Output is correct |
6 |
Correct |
963 ms |
126940 KB |
Output is correct |
7 |
Correct |
944 ms |
126916 KB |
Output is correct |
8 |
Correct |
825 ms |
128944 KB |
Output is correct |
9 |
Correct |
782 ms |
127612 KB |
Output is correct |
10 |
Correct |
658 ms |
127052 KB |
Output is correct |
11 |
Correct |
681 ms |
127112 KB |
Output is correct |
12 |
Correct |
892 ms |
126972 KB |
Output is correct |
13 |
Correct |
980 ms |
133816 KB |
Output is correct |
14 |
Correct |
949 ms |
133808 KB |
Output is correct |
15 |
Correct |
1025 ms |
133724 KB |
Output is correct |
16 |
Correct |
1032 ms |
133724 KB |
Output is correct |
17 |
Correct |
870 ms |
126968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
33204 KB |
Output is correct |
2 |
Correct |
17 ms |
33228 KB |
Output is correct |
3 |
Correct |
19 ms |
33204 KB |
Output is correct |
4 |
Correct |
20 ms |
33236 KB |
Output is correct |
5 |
Correct |
16 ms |
33204 KB |
Output is correct |
6 |
Correct |
17 ms |
33236 KB |
Output is correct |
7 |
Correct |
16 ms |
33236 KB |
Output is correct |
8 |
Correct |
18 ms |
33236 KB |
Output is correct |
9 |
Correct |
17 ms |
33156 KB |
Output is correct |
10 |
Correct |
23 ms |
34548 KB |
Output is correct |
11 |
Correct |
23 ms |
34496 KB |
Output is correct |
12 |
Correct |
21 ms |
34568 KB |
Output is correct |
13 |
Correct |
27 ms |
34644 KB |
Output is correct |
14 |
Correct |
24 ms |
34640 KB |
Output is correct |
15 |
Correct |
25 ms |
34664 KB |
Output is correct |
16 |
Correct |
831 ms |
126960 KB |
Output is correct |
17 |
Correct |
753 ms |
128828 KB |
Output is correct |
18 |
Correct |
745 ms |
127528 KB |
Output is correct |
19 |
Correct |
862 ms |
127100 KB |
Output is correct |
20 |
Correct |
904 ms |
127084 KB |
Output is correct |
21 |
Correct |
963 ms |
126940 KB |
Output is correct |
22 |
Correct |
944 ms |
126916 KB |
Output is correct |
23 |
Correct |
825 ms |
128944 KB |
Output is correct |
24 |
Correct |
782 ms |
127612 KB |
Output is correct |
25 |
Correct |
658 ms |
127052 KB |
Output is correct |
26 |
Correct |
681 ms |
127112 KB |
Output is correct |
27 |
Correct |
892 ms |
126972 KB |
Output is correct |
28 |
Correct |
980 ms |
133816 KB |
Output is correct |
29 |
Correct |
949 ms |
133808 KB |
Output is correct |
30 |
Correct |
1025 ms |
133724 KB |
Output is correct |
31 |
Correct |
1032 ms |
133724 KB |
Output is correct |
32 |
Correct |
870 ms |
126968 KB |
Output is correct |
33 |
Correct |
1173 ms |
127020 KB |
Output is correct |
34 |
Correct |
322 ms |
65136 KB |
Output is correct |
35 |
Correct |
1215 ms |
128992 KB |
Output is correct |
36 |
Correct |
1041 ms |
127480 KB |
Output is correct |
37 |
Correct |
1225 ms |
128300 KB |
Output is correct |
38 |
Correct |
1155 ms |
128012 KB |
Output is correct |
39 |
Correct |
1355 ms |
133576 KB |
Output is correct |
40 |
Correct |
1164 ms |
136960 KB |
Output is correct |
41 |
Correct |
965 ms |
127860 KB |
Output is correct |
42 |
Correct |
792 ms |
127556 KB |
Output is correct |
43 |
Correct |
1088 ms |
133516 KB |
Output is correct |
44 |
Correct |
1067 ms |
128392 KB |
Output is correct |
45 |
Correct |
989 ms |
133968 KB |
Output is correct |
46 |
Correct |
945 ms |
133560 KB |
Output is correct |
47 |
Correct |
986 ms |
133868 KB |
Output is correct |
48 |
Correct |
1014 ms |
133816 KB |
Output is correct |
49 |
Correct |
1046 ms |
133924 KB |
Output is correct |
50 |
Correct |
1034 ms |
133844 KB |
Output is correct |
51 |
Correct |
1082 ms |
136792 KB |
Output is correct |
52 |
Correct |
1124 ms |
136780 KB |
Output is correct |