#include <bits/stdc++.h>
using namespace std ;
const int MAX = 5000 + 10 ;
int arr[MAX] ;
int n ;
vector<int>v[MAX] ;
bitset<MAX>s[MAX] ;
int L[MAX] , R[MAX] ;
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n ;
for(int i = 1 ; i <= n-1 ; ++i)
cin>>arr[i] ;
for(int i = 1 ; i <= n ; ++i)
{
int sz ;
cin>>sz ;
v[i].resize(sz) ;
for(auto &x : v[i])
cin>>x , s[i][x] = 1 ;
}
for(int i = 1 ; i <= n ; ++i)
L[i] = R[i] = i ;
for(int k = 0 ; k < n+1 ; ++k)
{
for(int i = 1 ; i <= n ; ++i)
{
if(L[i]-1 >= 1 && s[i][arr[L[i]-1]])
L[i]-- , s[i] |= s[L[i]] ;
if(R[i]+1 <= n && s[i][arr[R[i]]])
R[i]++ , s[i] |= s[R[i]] ;
}
}
int q ;
cin>>q ;
while(q--)
{
int x , y ;
cin>>x>>y ;
if(y >= L[x] && y <= R[x])
cout<<"YES\n" ;
else
cout<<"NO\n" ;
}
return 0 ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1748 KB |
Output is correct |
2 |
Correct |
159 ms |
2420 KB |
Output is correct |
3 |
Correct |
691 ms |
3724 KB |
Output is correct |
4 |
Correct |
16 ms |
1780 KB |
Output is correct |
5 |
Correct |
141 ms |
1764 KB |
Output is correct |
6 |
Correct |
33 ms |
1852 KB |
Output is correct |
7 |
Correct |
47 ms |
1828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1748 KB |
Output is correct |
2 |
Correct |
159 ms |
2420 KB |
Output is correct |
3 |
Correct |
691 ms |
3724 KB |
Output is correct |
4 |
Correct |
16 ms |
1780 KB |
Output is correct |
5 |
Correct |
141 ms |
1764 KB |
Output is correct |
6 |
Correct |
33 ms |
1852 KB |
Output is correct |
7 |
Correct |
47 ms |
1828 KB |
Output is correct |
8 |
Correct |
97 ms |
7648 KB |
Output is correct |
9 |
Correct |
82 ms |
7544 KB |
Output is correct |
10 |
Correct |
232 ms |
8548 KB |
Output is correct |
11 |
Correct |
764 ms |
10116 KB |
Output is correct |
12 |
Correct |
96 ms |
6844 KB |
Output is correct |
13 |
Correct |
78 ms |
7824 KB |
Output is correct |
14 |
Correct |
84 ms |
7808 KB |
Output is correct |
15 |
Correct |
143 ms |
7800 KB |
Output is correct |
16 |
Correct |
209 ms |
7636 KB |
Output is correct |
17 |
Correct |
77 ms |
7852 KB |
Output is correct |
18 |
Correct |
85 ms |
7820 KB |
Output is correct |
19 |
Correct |
100 ms |
7848 KB |
Output is correct |
20 |
Correct |
183 ms |
7764 KB |
Output is correct |
21 |
Correct |
209 ms |
7632 KB |
Output is correct |
22 |
Correct |
134 ms |
7764 KB |
Output is correct |
23 |
Correct |
109 ms |
7556 KB |
Output is correct |
24 |
Correct |
112 ms |
7584 KB |
Output is correct |
25 |
Correct |
121 ms |
7584 KB |
Output is correct |
26 |
Correct |
100 ms |
7652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
664 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1748 KB |
Output is correct |
2 |
Correct |
159 ms |
2420 KB |
Output is correct |
3 |
Correct |
691 ms |
3724 KB |
Output is correct |
4 |
Correct |
16 ms |
1780 KB |
Output is correct |
5 |
Correct |
141 ms |
1764 KB |
Output is correct |
6 |
Correct |
33 ms |
1852 KB |
Output is correct |
7 |
Correct |
47 ms |
1828 KB |
Output is correct |
8 |
Correct |
97 ms |
7648 KB |
Output is correct |
9 |
Correct |
82 ms |
7544 KB |
Output is correct |
10 |
Correct |
232 ms |
8548 KB |
Output is correct |
11 |
Correct |
764 ms |
10116 KB |
Output is correct |
12 |
Correct |
96 ms |
6844 KB |
Output is correct |
13 |
Correct |
78 ms |
7824 KB |
Output is correct |
14 |
Correct |
84 ms |
7808 KB |
Output is correct |
15 |
Correct |
143 ms |
7800 KB |
Output is correct |
16 |
Correct |
209 ms |
7636 KB |
Output is correct |
17 |
Correct |
77 ms |
7852 KB |
Output is correct |
18 |
Correct |
85 ms |
7820 KB |
Output is correct |
19 |
Correct |
100 ms |
7848 KB |
Output is correct |
20 |
Correct |
183 ms |
7764 KB |
Output is correct |
21 |
Correct |
209 ms |
7632 KB |
Output is correct |
22 |
Correct |
134 ms |
7764 KB |
Output is correct |
23 |
Correct |
109 ms |
7556 KB |
Output is correct |
24 |
Correct |
112 ms |
7584 KB |
Output is correct |
25 |
Correct |
121 ms |
7584 KB |
Output is correct |
26 |
Correct |
100 ms |
7652 KB |
Output is correct |
27 |
Runtime error |
2 ms |
664 KB |
Execution killed with signal 11 |
28 |
Halted |
0 ms |
0 KB |
- |