#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 (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 |
4 ms |
25176 KB |
Output is correct |
2 |
Correct |
4 ms |
25180 KB |
Output is correct |
3 |
Correct |
5 ms |
25432 KB |
Output is correct |
4 |
Correct |
6 ms |
25180 KB |
Output is correct |
5 |
Correct |
4 ms |
25032 KB |
Output is correct |
6 |
Correct |
4 ms |
25176 KB |
Output is correct |
7 |
Correct |
6 ms |
24924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
25176 KB |
Output is correct |
2 |
Correct |
4 ms |
25180 KB |
Output is correct |
3 |
Correct |
5 ms |
25432 KB |
Output is correct |
4 |
Correct |
6 ms |
25180 KB |
Output is correct |
5 |
Correct |
4 ms |
25032 KB |
Output is correct |
6 |
Correct |
4 ms |
25176 KB |
Output is correct |
7 |
Correct |
6 ms |
24924 KB |
Output is correct |
8 |
Correct |
64 ms |
26452 KB |
Output is correct |
9 |
Correct |
64 ms |
26448 KB |
Output is correct |
10 |
Correct |
95 ms |
26664 KB |
Output is correct |
11 |
Correct |
71 ms |
26952 KB |
Output is correct |
12 |
Correct |
59 ms |
26708 KB |
Output is correct |
13 |
Correct |
64 ms |
26648 KB |
Output is correct |
14 |
Correct |
54 ms |
26768 KB |
Output is correct |
15 |
Correct |
56 ms |
26960 KB |
Output is correct |
16 |
Correct |
53 ms |
26964 KB |
Output is correct |
17 |
Correct |
54 ms |
26704 KB |
Output is correct |
18 |
Correct |
100 ms |
26704 KB |
Output is correct |
19 |
Correct |
91 ms |
26708 KB |
Output is correct |
20 |
Correct |
75 ms |
26860 KB |
Output is correct |
21 |
Correct |
57 ms |
26964 KB |
Output is correct |
22 |
Correct |
64 ms |
26708 KB |
Output is correct |
23 |
Correct |
68 ms |
26616 KB |
Output is correct |
24 |
Correct |
97 ms |
22608 KB |
Output is correct |
25 |
Correct |
71 ms |
22612 KB |
Output is correct |
26 |
Correct |
58 ms |
20564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
26696 KB |
Output is correct |
2 |
Correct |
104 ms |
25108 KB |
Output is correct |
3 |
Correct |
117 ms |
25192 KB |
Output is correct |
4 |
Correct |
135 ms |
26712 KB |
Output is correct |
5 |
Correct |
105 ms |
25060 KB |
Output is correct |
6 |
Correct |
112 ms |
26960 KB |
Output is correct |
7 |
Correct |
79 ms |
25460 KB |
Output is correct |
8 |
Correct |
100 ms |
30356 KB |
Output is correct |
9 |
Correct |
92 ms |
30352 KB |
Output is correct |
10 |
Correct |
83 ms |
30192 KB |
Output is correct |
11 |
Correct |
99 ms |
30340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
25176 KB |
Output is correct |
2 |
Correct |
4 ms |
25180 KB |
Output is correct |
3 |
Correct |
5 ms |
25432 KB |
Output is correct |
4 |
Correct |
6 ms |
25180 KB |
Output is correct |
5 |
Correct |
4 ms |
25032 KB |
Output is correct |
6 |
Correct |
4 ms |
25176 KB |
Output is correct |
7 |
Correct |
6 ms |
24924 KB |
Output is correct |
8 |
Correct |
64 ms |
26452 KB |
Output is correct |
9 |
Correct |
64 ms |
26448 KB |
Output is correct |
10 |
Correct |
95 ms |
26664 KB |
Output is correct |
11 |
Correct |
71 ms |
26952 KB |
Output is correct |
12 |
Correct |
59 ms |
26708 KB |
Output is correct |
13 |
Correct |
64 ms |
26648 KB |
Output is correct |
14 |
Correct |
54 ms |
26768 KB |
Output is correct |
15 |
Correct |
56 ms |
26960 KB |
Output is correct |
16 |
Correct |
53 ms |
26964 KB |
Output is correct |
17 |
Correct |
54 ms |
26704 KB |
Output is correct |
18 |
Correct |
100 ms |
26704 KB |
Output is correct |
19 |
Correct |
91 ms |
26708 KB |
Output is correct |
20 |
Correct |
75 ms |
26860 KB |
Output is correct |
21 |
Correct |
57 ms |
26964 KB |
Output is correct |
22 |
Correct |
64 ms |
26708 KB |
Output is correct |
23 |
Correct |
68 ms |
26616 KB |
Output is correct |
24 |
Correct |
97 ms |
22608 KB |
Output is correct |
25 |
Correct |
71 ms |
22612 KB |
Output is correct |
26 |
Correct |
58 ms |
20564 KB |
Output is correct |
27 |
Correct |
106 ms |
26696 KB |
Output is correct |
28 |
Correct |
104 ms |
25108 KB |
Output is correct |
29 |
Correct |
117 ms |
25192 KB |
Output is correct |
30 |
Correct |
135 ms |
26712 KB |
Output is correct |
31 |
Correct |
105 ms |
25060 KB |
Output is correct |
32 |
Correct |
112 ms |
26960 KB |
Output is correct |
33 |
Correct |
79 ms |
25460 KB |
Output is correct |
34 |
Correct |
100 ms |
30356 KB |
Output is correct |
35 |
Correct |
92 ms |
30352 KB |
Output is correct |
36 |
Correct |
83 ms |
30192 KB |
Output is correct |
37 |
Correct |
99 ms |
30340 KB |
Output is correct |
38 |
Correct |
141 ms |
39508 KB |
Output is correct |
39 |
Correct |
226 ms |
42836 KB |
Output is correct |
40 |
Correct |
142 ms |
35940 KB |
Output is correct |
41 |
Correct |
148 ms |
43092 KB |
Output is correct |
42 |
Correct |
102 ms |
30040 KB |
Output is correct |
43 |
Correct |
91 ms |
30072 KB |
Output is correct |
44 |
Correct |
107 ms |
33204 KB |
Output is correct |
45 |
Correct |
109 ms |
33108 KB |
Output is correct |
46 |
Correct |
116 ms |
33204 KB |
Output is correct |
47 |
Correct |
92 ms |
30028 KB |
Output is correct |
48 |
Correct |
96 ms |
30032 KB |
Output is correct |
49 |
Correct |
156 ms |
33212 KB |
Output is correct |
50 |
Correct |
114 ms |
33260 KB |
Output is correct |
51 |
Correct |
118 ms |
33108 KB |
Output is correct |
52 |
Correct |
114 ms |
33060 KB |
Output is correct |
53 |
Correct |
129 ms |
36176 KB |
Output is correct |
54 |
Correct |
151 ms |
39508 KB |
Output is correct |
55 |
Correct |
134 ms |
36180 KB |
Output is correct |