#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--;
curl = min(curl, l[curl]);
curr = max(curr, r[curr]);
}
else if (curr < N && pre[curr] >= curl){
if (l[pre[curr]] <= u && r[pre[curr]] >= u){
l[u] = l[pre[curr]];
r[u] = r[pre[curr]];
return;
}
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 |
9 ms |
12376 KB |
Output is correct |
2 |
Correct |
8 ms |
12380 KB |
Output is correct |
3 |
Correct |
13 ms |
12408 KB |
Output is correct |
4 |
Correct |
6 ms |
12380 KB |
Output is correct |
5 |
Correct |
8 ms |
12380 KB |
Output is correct |
6 |
Correct |
8 ms |
12348 KB |
Output is correct |
7 |
Correct |
7 ms |
12380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
12376 KB |
Output is correct |
2 |
Correct |
8 ms |
12380 KB |
Output is correct |
3 |
Correct |
13 ms |
12408 KB |
Output is correct |
4 |
Correct |
6 ms |
12380 KB |
Output is correct |
5 |
Correct |
8 ms |
12380 KB |
Output is correct |
6 |
Correct |
8 ms |
12348 KB |
Output is correct |
7 |
Correct |
7 ms |
12380 KB |
Output is correct |
8 |
Correct |
64 ms |
18260 KB |
Output is correct |
9 |
Correct |
85 ms |
18004 KB |
Output is correct |
10 |
Correct |
69 ms |
18516 KB |
Output is correct |
11 |
Correct |
74 ms |
18776 KB |
Output is correct |
12 |
Correct |
63 ms |
17744 KB |
Output is correct |
13 |
Correct |
59 ms |
18260 KB |
Output is correct |
14 |
Correct |
59 ms |
18260 KB |
Output is correct |
15 |
Correct |
59 ms |
18256 KB |
Output is correct |
16 |
Correct |
65 ms |
18060 KB |
Output is correct |
17 |
Correct |
59 ms |
18264 KB |
Output is correct |
18 |
Correct |
59 ms |
18264 KB |
Output is correct |
19 |
Correct |
61 ms |
18256 KB |
Output is correct |
20 |
Correct |
65 ms |
18392 KB |
Output is correct |
21 |
Correct |
58 ms |
18224 KB |
Output is correct |
22 |
Correct |
56 ms |
18256 KB |
Output is correct |
23 |
Correct |
59 ms |
18040 KB |
Output is correct |
24 |
Correct |
68 ms |
18168 KB |
Output is correct |
25 |
Correct |
71 ms |
18116 KB |
Output is correct |
26 |
Correct |
68 ms |
18004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
437 ms |
27108 KB |
Output is correct |
2 |
Correct |
803 ms |
26968 KB |
Output is correct |
3 |
Correct |
1523 ms |
26752 KB |
Output is correct |
4 |
Correct |
533 ms |
26960 KB |
Output is correct |
5 |
Correct |
613 ms |
26960 KB |
Output is correct |
6 |
Correct |
1036 ms |
26192 KB |
Output is correct |
7 |
Correct |
2906 ms |
25908 KB |
Output is correct |
8 |
Execution timed out |
3038 ms |
18776 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
12376 KB |
Output is correct |
2 |
Correct |
8 ms |
12380 KB |
Output is correct |
3 |
Correct |
13 ms |
12408 KB |
Output is correct |
4 |
Correct |
6 ms |
12380 KB |
Output is correct |
5 |
Correct |
8 ms |
12380 KB |
Output is correct |
6 |
Correct |
8 ms |
12348 KB |
Output is correct |
7 |
Correct |
7 ms |
12380 KB |
Output is correct |
8 |
Correct |
64 ms |
18260 KB |
Output is correct |
9 |
Correct |
85 ms |
18004 KB |
Output is correct |
10 |
Correct |
69 ms |
18516 KB |
Output is correct |
11 |
Correct |
74 ms |
18776 KB |
Output is correct |
12 |
Correct |
63 ms |
17744 KB |
Output is correct |
13 |
Correct |
59 ms |
18260 KB |
Output is correct |
14 |
Correct |
59 ms |
18260 KB |
Output is correct |
15 |
Correct |
59 ms |
18256 KB |
Output is correct |
16 |
Correct |
65 ms |
18060 KB |
Output is correct |
17 |
Correct |
59 ms |
18264 KB |
Output is correct |
18 |
Correct |
59 ms |
18264 KB |
Output is correct |
19 |
Correct |
61 ms |
18256 KB |
Output is correct |
20 |
Correct |
65 ms |
18392 KB |
Output is correct |
21 |
Correct |
58 ms |
18224 KB |
Output is correct |
22 |
Correct |
56 ms |
18256 KB |
Output is correct |
23 |
Correct |
59 ms |
18040 KB |
Output is correct |
24 |
Correct |
68 ms |
18168 KB |
Output is correct |
25 |
Correct |
71 ms |
18116 KB |
Output is correct |
26 |
Correct |
68 ms |
18004 KB |
Output is correct |
27 |
Correct |
437 ms |
27108 KB |
Output is correct |
28 |
Correct |
803 ms |
26968 KB |
Output is correct |
29 |
Correct |
1523 ms |
26752 KB |
Output is correct |
30 |
Correct |
533 ms |
26960 KB |
Output is correct |
31 |
Correct |
613 ms |
26960 KB |
Output is correct |
32 |
Correct |
1036 ms |
26192 KB |
Output is correct |
33 |
Correct |
2906 ms |
25908 KB |
Output is correct |
34 |
Execution timed out |
3038 ms |
18776 KB |
Time limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |