#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12380 KB |
Output is correct |
2 |
Correct |
6 ms |
12456 KB |
Output is correct |
3 |
Correct |
7 ms |
12316 KB |
Output is correct |
4 |
Correct |
6 ms |
12376 KB |
Output is correct |
5 |
Correct |
6 ms |
12200 KB |
Output is correct |
6 |
Correct |
6 ms |
12344 KB |
Output is correct |
7 |
Correct |
7 ms |
12380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12380 KB |
Output is correct |
2 |
Correct |
6 ms |
12456 KB |
Output is correct |
3 |
Correct |
7 ms |
12316 KB |
Output is correct |
4 |
Correct |
6 ms |
12376 KB |
Output is correct |
5 |
Correct |
6 ms |
12200 KB |
Output is correct |
6 |
Correct |
6 ms |
12344 KB |
Output is correct |
7 |
Correct |
7 ms |
12380 KB |
Output is correct |
8 |
Correct |
64 ms |
13716 KB |
Output is correct |
9 |
Correct |
71 ms |
13636 KB |
Output is correct |
10 |
Correct |
61 ms |
13912 KB |
Output is correct |
11 |
Correct |
63 ms |
14208 KB |
Output is correct |
12 |
Correct |
54 ms |
13904 KB |
Output is correct |
13 |
Correct |
68 ms |
14164 KB |
Output is correct |
14 |
Correct |
56 ms |
13908 KB |
Output is correct |
15 |
Correct |
56 ms |
14164 KB |
Output is correct |
16 |
Correct |
59 ms |
14164 KB |
Output is correct |
17 |
Correct |
56 ms |
13908 KB |
Output is correct |
18 |
Correct |
60 ms |
13904 KB |
Output is correct |
19 |
Correct |
56 ms |
13908 KB |
Output is correct |
20 |
Correct |
59 ms |
14160 KB |
Output is correct |
21 |
Correct |
62 ms |
14284 KB |
Output is correct |
22 |
Correct |
56 ms |
13904 KB |
Output is correct |
23 |
Correct |
64 ms |
13840 KB |
Output is correct |
24 |
Correct |
59 ms |
13908 KB |
Output is correct |
25 |
Correct |
58 ms |
13932 KB |
Output is correct |
26 |
Correct |
60 ms |
13904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
107 ms |
19796 KB |
Output is correct |
2 |
Correct |
106 ms |
19796 KB |
Output is correct |
3 |
Correct |
104 ms |
19776 KB |
Output is correct |
4 |
Correct |
100 ms |
19792 KB |
Output is correct |
5 |
Correct |
126 ms |
19632 KB |
Output is correct |
6 |
Correct |
87 ms |
19796 KB |
Output is correct |
7 |
Correct |
83 ms |
20052 KB |
Output is correct |
8 |
Correct |
82 ms |
20052 KB |
Output is correct |
9 |
Correct |
80 ms |
20048 KB |
Output is correct |
10 |
Correct |
90 ms |
19904 KB |
Output is correct |
11 |
Correct |
105 ms |
23376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12380 KB |
Output is correct |
2 |
Correct |
6 ms |
12456 KB |
Output is correct |
3 |
Correct |
7 ms |
12316 KB |
Output is correct |
4 |
Correct |
6 ms |
12376 KB |
Output is correct |
5 |
Correct |
6 ms |
12200 KB |
Output is correct |
6 |
Correct |
6 ms |
12344 KB |
Output is correct |
7 |
Correct |
7 ms |
12380 KB |
Output is correct |
8 |
Correct |
64 ms |
13716 KB |
Output is correct |
9 |
Correct |
71 ms |
13636 KB |
Output is correct |
10 |
Correct |
61 ms |
13912 KB |
Output is correct |
11 |
Correct |
63 ms |
14208 KB |
Output is correct |
12 |
Correct |
54 ms |
13904 KB |
Output is correct |
13 |
Correct |
68 ms |
14164 KB |
Output is correct |
14 |
Correct |
56 ms |
13908 KB |
Output is correct |
15 |
Correct |
56 ms |
14164 KB |
Output is correct |
16 |
Correct |
59 ms |
14164 KB |
Output is correct |
17 |
Correct |
56 ms |
13908 KB |
Output is correct |
18 |
Correct |
60 ms |
13904 KB |
Output is correct |
19 |
Correct |
56 ms |
13908 KB |
Output is correct |
20 |
Correct |
59 ms |
14160 KB |
Output is correct |
21 |
Correct |
62 ms |
14284 KB |
Output is correct |
22 |
Correct |
56 ms |
13904 KB |
Output is correct |
23 |
Correct |
64 ms |
13840 KB |
Output is correct |
24 |
Correct |
59 ms |
13908 KB |
Output is correct |
25 |
Correct |
58 ms |
13932 KB |
Output is correct |
26 |
Correct |
60 ms |
13904 KB |
Output is correct |
27 |
Correct |
107 ms |
19796 KB |
Output is correct |
28 |
Correct |
106 ms |
19796 KB |
Output is correct |
29 |
Correct |
104 ms |
19776 KB |
Output is correct |
30 |
Correct |
100 ms |
19792 KB |
Output is correct |
31 |
Correct |
126 ms |
19632 KB |
Output is correct |
32 |
Correct |
87 ms |
19796 KB |
Output is correct |
33 |
Correct |
83 ms |
20052 KB |
Output is correct |
34 |
Correct |
82 ms |
20052 KB |
Output is correct |
35 |
Correct |
80 ms |
20048 KB |
Output is correct |
36 |
Correct |
90 ms |
19904 KB |
Output is correct |
37 |
Correct |
105 ms |
23376 KB |
Output is correct |
38 |
Correct |
166 ms |
43424 KB |
Output is correct |
39 |
Correct |
155 ms |
48720 KB |
Output is correct |
40 |
Correct |
148 ms |
36944 KB |
Output is correct |
41 |
Correct |
167 ms |
48468 KB |
Output is correct |
42 |
Correct |
94 ms |
23832 KB |
Output is correct |
43 |
Correct |
90 ms |
23888 KB |
Output is correct |
44 |
Correct |
122 ms |
31228 KB |
Output is correct |
45 |
Correct |
120 ms |
31060 KB |
Output is correct |
46 |
Correct |
138 ms |
30912 KB |
Output is correct |
47 |
Correct |
100 ms |
23656 KB |
Output is correct |
48 |
Correct |
94 ms |
23672 KB |
Output is correct |
49 |
Correct |
118 ms |
31060 KB |
Output is correct |
50 |
Correct |
117 ms |
31060 KB |
Output is correct |
51 |
Correct |
129 ms |
31052 KB |
Output is correct |
52 |
Correct |
120 ms |
30312 KB |
Output is correct |
53 |
Correct |
150 ms |
36944 KB |
Output is correct |
54 |
Correct |
166 ms |
43568 KB |
Output is correct |
55 |
Correct |
138 ms |
37208 KB |
Output is correct |