#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){
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 |
12380 KB |
Output is correct |
2 |
Correct |
8 ms |
12476 KB |
Output is correct |
3 |
Correct |
14 ms |
12632 KB |
Output is correct |
4 |
Correct |
7 ms |
12380 KB |
Output is correct |
5 |
Correct |
7 ms |
12376 KB |
Output is correct |
6 |
Correct |
7 ms |
12380 KB |
Output is correct |
7 |
Correct |
7 ms |
12376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12380 KB |
Output is correct |
2 |
Correct |
8 ms |
12476 KB |
Output is correct |
3 |
Correct |
14 ms |
12632 KB |
Output is correct |
4 |
Correct |
7 ms |
12380 KB |
Output is correct |
5 |
Correct |
7 ms |
12376 KB |
Output is correct |
6 |
Correct |
7 ms |
12380 KB |
Output is correct |
7 |
Correct |
7 ms |
12376 KB |
Output is correct |
8 |
Correct |
71 ms |
18260 KB |
Output is correct |
9 |
Correct |
68 ms |
18000 KB |
Output is correct |
10 |
Correct |
66 ms |
18516 KB |
Output is correct |
11 |
Correct |
69 ms |
19000 KB |
Output is correct |
12 |
Correct |
61 ms |
17744 KB |
Output is correct |
13 |
Correct |
61 ms |
18304 KB |
Output is correct |
14 |
Correct |
59 ms |
18260 KB |
Output is correct |
15 |
Correct |
61 ms |
18256 KB |
Output is correct |
16 |
Correct |
57 ms |
18260 KB |
Output is correct |
17 |
Correct |
58 ms |
18432 KB |
Output is correct |
18 |
Correct |
60 ms |
18256 KB |
Output is correct |
19 |
Correct |
58 ms |
18260 KB |
Output is correct |
20 |
Correct |
58 ms |
18260 KB |
Output is correct |
21 |
Correct |
58 ms |
18200 KB |
Output is correct |
22 |
Correct |
57 ms |
18284 KB |
Output is correct |
23 |
Correct |
62 ms |
18004 KB |
Output is correct |
24 |
Correct |
62 ms |
18020 KB |
Output is correct |
25 |
Correct |
59 ms |
18000 KB |
Output is correct |
26 |
Correct |
63 ms |
18164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
572 ms |
26964 KB |
Output is correct |
2 |
Correct |
1122 ms |
26968 KB |
Output is correct |
3 |
Correct |
2349 ms |
26704 KB |
Output is correct |
4 |
Correct |
771 ms |
26968 KB |
Output is correct |
5 |
Correct |
887 ms |
26860 KB |
Output is correct |
6 |
Correct |
2538 ms |
26148 KB |
Output is correct |
7 |
Execution timed out |
3014 ms |
18512 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12380 KB |
Output is correct |
2 |
Correct |
8 ms |
12476 KB |
Output is correct |
3 |
Correct |
14 ms |
12632 KB |
Output is correct |
4 |
Correct |
7 ms |
12380 KB |
Output is correct |
5 |
Correct |
7 ms |
12376 KB |
Output is correct |
6 |
Correct |
7 ms |
12380 KB |
Output is correct |
7 |
Correct |
7 ms |
12376 KB |
Output is correct |
8 |
Correct |
71 ms |
18260 KB |
Output is correct |
9 |
Correct |
68 ms |
18000 KB |
Output is correct |
10 |
Correct |
66 ms |
18516 KB |
Output is correct |
11 |
Correct |
69 ms |
19000 KB |
Output is correct |
12 |
Correct |
61 ms |
17744 KB |
Output is correct |
13 |
Correct |
61 ms |
18304 KB |
Output is correct |
14 |
Correct |
59 ms |
18260 KB |
Output is correct |
15 |
Correct |
61 ms |
18256 KB |
Output is correct |
16 |
Correct |
57 ms |
18260 KB |
Output is correct |
17 |
Correct |
58 ms |
18432 KB |
Output is correct |
18 |
Correct |
60 ms |
18256 KB |
Output is correct |
19 |
Correct |
58 ms |
18260 KB |
Output is correct |
20 |
Correct |
58 ms |
18260 KB |
Output is correct |
21 |
Correct |
58 ms |
18200 KB |
Output is correct |
22 |
Correct |
57 ms |
18284 KB |
Output is correct |
23 |
Correct |
62 ms |
18004 KB |
Output is correct |
24 |
Correct |
62 ms |
18020 KB |
Output is correct |
25 |
Correct |
59 ms |
18000 KB |
Output is correct |
26 |
Correct |
63 ms |
18164 KB |
Output is correct |
27 |
Correct |
572 ms |
26964 KB |
Output is correct |
28 |
Correct |
1122 ms |
26968 KB |
Output is correct |
29 |
Correct |
2349 ms |
26704 KB |
Output is correct |
30 |
Correct |
771 ms |
26968 KB |
Output is correct |
31 |
Correct |
887 ms |
26860 KB |
Output is correct |
32 |
Correct |
2538 ms |
26148 KB |
Output is correct |
33 |
Execution timed out |
3014 ms |
18512 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |