#include <bits/stdc++.h>
using namespace std;
const int NM = 5e5;
int N, Q, C[NM+5], B[NM+5], pre[NM+5], nxt[NM+5], lst[NM+5];
vector <int> arr[NM+5];
int l[NM+5], r[NM+5];
void solve(int u){
int curl = u, curr = u;
while (true){
if (curl > 1 && nxt[curl] <= curr){
curl--;
if (l[curl] <= u && r[curl] >= u){
l[u] = l[curl];
r[u] = r[curl];
return;
}
}
else if (curr < N && pre[curr] >= curl){
curr++;
}
else break;
}
l[u] = curl, r[u] = curr;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N;
for (int i = 1; i < N; i++) cin >> C[i];
for (int i = 1; i <= N; i++){
cin >> B[i];
arr[i].resize(B[i]);
for (int j = 0; j < B[i]; j++) cin >> arr[i][j];
}
for (int i = 1; i < N; i++){
for (int x : arr[i]) lst[x] = i;
pre[i] = lst[C[i]];
}
for (int i = 1; i <= N; i++) lst[i] = N+1;
for (int i = N; i > 1; i--){
for (int x : arr[i]) lst[x] = i;
nxt[i] = lst[C[i-1]];
}
for (int i = 1; i <= N; i++) solve(i);
cin >> Q;
while (Q--){
int x, y; cin >> x >> y;
if (l[x] <= y && r[x] >= y){
cout << "YES\n";
continue;
}
cout << "NO\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12220 KB |
Output is correct |
2 |
Correct |
7 ms |
12376 KB |
Output is correct |
3 |
Correct |
7 ms |
12636 KB |
Output is correct |
4 |
Correct |
6 ms |
12380 KB |
Output is correct |
5 |
Correct |
7 ms |
12380 KB |
Output is correct |
6 |
Correct |
7 ms |
12340 KB |
Output is correct |
7 |
Correct |
7 ms |
12376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12220 KB |
Output is correct |
2 |
Correct |
7 ms |
12376 KB |
Output is correct |
3 |
Correct |
7 ms |
12636 KB |
Output is correct |
4 |
Correct |
6 ms |
12380 KB |
Output is correct |
5 |
Correct |
7 ms |
12380 KB |
Output is correct |
6 |
Correct |
7 ms |
12340 KB |
Output is correct |
7 |
Correct |
7 ms |
12376 KB |
Output is correct |
8 |
Correct |
66 ms |
18264 KB |
Output is correct |
9 |
Correct |
66 ms |
18000 KB |
Output is correct |
10 |
Correct |
70 ms |
18516 KB |
Output is correct |
11 |
Correct |
66 ms |
18768 KB |
Output is correct |
12 |
Correct |
67 ms |
17748 KB |
Output is correct |
13 |
Correct |
60 ms |
18256 KB |
Output is correct |
14 |
Correct |
71 ms |
18492 KB |
Output is correct |
15 |
Correct |
74 ms |
18260 KB |
Output is correct |
16 |
Correct |
57 ms |
18204 KB |
Output is correct |
17 |
Correct |
60 ms |
18432 KB |
Output is correct |
18 |
Correct |
67 ms |
18256 KB |
Output is correct |
19 |
Correct |
61 ms |
18388 KB |
Output is correct |
20 |
Correct |
92 ms |
18232 KB |
Output is correct |
21 |
Correct |
57 ms |
18208 KB |
Output is correct |
22 |
Correct |
58 ms |
18260 KB |
Output is correct |
23 |
Correct |
62 ms |
18004 KB |
Output is correct |
24 |
Correct |
60 ms |
18004 KB |
Output is correct |
25 |
Correct |
74 ms |
18000 KB |
Output is correct |
26 |
Correct |
82 ms |
18000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
27212 KB |
Output is correct |
2 |
Correct |
105 ms |
26812 KB |
Output is correct |
3 |
Correct |
114 ms |
26680 KB |
Output is correct |
4 |
Correct |
104 ms |
27096 KB |
Output is correct |
5 |
Correct |
120 ms |
26960 KB |
Output is correct |
6 |
Correct |
125 ms |
26252 KB |
Output is correct |
7 |
Correct |
118 ms |
25940 KB |
Output is correct |
8 |
Correct |
86 ms |
25936 KB |
Output is correct |
9 |
Correct |
89 ms |
25936 KB |
Output is correct |
10 |
Correct |
86 ms |
25940 KB |
Output is correct |
11 |
Correct |
93 ms |
26192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12220 KB |
Output is correct |
2 |
Correct |
7 ms |
12376 KB |
Output is correct |
3 |
Correct |
7 ms |
12636 KB |
Output is correct |
4 |
Correct |
6 ms |
12380 KB |
Output is correct |
5 |
Correct |
7 ms |
12380 KB |
Output is correct |
6 |
Correct |
7 ms |
12340 KB |
Output is correct |
7 |
Correct |
7 ms |
12376 KB |
Output is correct |
8 |
Correct |
66 ms |
18264 KB |
Output is correct |
9 |
Correct |
66 ms |
18000 KB |
Output is correct |
10 |
Correct |
70 ms |
18516 KB |
Output is correct |
11 |
Correct |
66 ms |
18768 KB |
Output is correct |
12 |
Correct |
67 ms |
17748 KB |
Output is correct |
13 |
Correct |
60 ms |
18256 KB |
Output is correct |
14 |
Correct |
71 ms |
18492 KB |
Output is correct |
15 |
Correct |
74 ms |
18260 KB |
Output is correct |
16 |
Correct |
57 ms |
18204 KB |
Output is correct |
17 |
Correct |
60 ms |
18432 KB |
Output is correct |
18 |
Correct |
67 ms |
18256 KB |
Output is correct |
19 |
Correct |
61 ms |
18388 KB |
Output is correct |
20 |
Correct |
92 ms |
18232 KB |
Output is correct |
21 |
Correct |
57 ms |
18208 KB |
Output is correct |
22 |
Correct |
58 ms |
18260 KB |
Output is correct |
23 |
Correct |
62 ms |
18004 KB |
Output is correct |
24 |
Correct |
60 ms |
18004 KB |
Output is correct |
25 |
Correct |
74 ms |
18000 KB |
Output is correct |
26 |
Correct |
82 ms |
18000 KB |
Output is correct |
27 |
Correct |
102 ms |
27212 KB |
Output is correct |
28 |
Correct |
105 ms |
26812 KB |
Output is correct |
29 |
Correct |
114 ms |
26680 KB |
Output is correct |
30 |
Correct |
104 ms |
27096 KB |
Output is correct |
31 |
Correct |
120 ms |
26960 KB |
Output is correct |
32 |
Correct |
125 ms |
26252 KB |
Output is correct |
33 |
Correct |
118 ms |
25940 KB |
Output is correct |
34 |
Correct |
86 ms |
25936 KB |
Output is correct |
35 |
Correct |
89 ms |
25936 KB |
Output is correct |
36 |
Correct |
86 ms |
25940 KB |
Output is correct |
37 |
Correct |
93 ms |
26192 KB |
Output is correct |
38 |
Correct |
157 ms |
48724 KB |
Output is correct |
39 |
Correct |
171 ms |
54272 KB |
Output is correct |
40 |
Correct |
147 ms |
41868 KB |
Output is correct |
41 |
Correct |
182 ms |
52676 KB |
Output is correct |
42 |
Correct |
92 ms |
27216 KB |
Output is correct |
43 |
Correct |
89 ms |
27216 KB |
Output is correct |
44 |
Correct |
123 ms |
35532 KB |
Output is correct |
45 |
Correct |
124 ms |
35896 KB |
Output is correct |
46 |
Correct |
117 ms |
35924 KB |
Output is correct |
47 |
Correct |
88 ms |
27284 KB |
Output is correct |
48 |
Correct |
93 ms |
27052 KB |
Output is correct |
49 |
Correct |
151 ms |
35772 KB |
Output is correct |
50 |
Correct |
120 ms |
35668 KB |
Output is correct |
51 |
Correct |
120 ms |
36136 KB |
Output is correct |
52 |
Correct |
119 ms |
34604 KB |
Output is correct |
53 |
Correct |
140 ms |
42052 KB |
Output is correct |
54 |
Correct |
156 ms |
49576 KB |
Output is correct |
55 |
Correct |
135 ms |
42320 KB |
Output is correct |