#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include <bits/stdc++.h>
using namespace std;
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n;
cin>>n;
int arr[n-1];
for(int i= 0;i<n-1;i++){
cin>>arr[i];
}
vector<vector<int>>v;
for(int i = 0;i<n;i++){
int z;cin>>z;
vector<int> tmp;
for(int j= 0;j<z;j++){
int x;cin>>x;
tmp.push_back(x);
}
v.push_back(tmp);
}
int nd[n+1];
for(int i = 0;i<=n;i++)nd[i] = n;
int valr[n];
int vall[n];
for(int i = n-1;i>=1;i--){
for(auto j:v[i]){
nd[j]=i;
}
valr[i] = nd[arr[i-1]];
}
for(int i = 0;i<=n;i++)nd[i] = -1;
for(int i = 0;i<n-1;i++){
for(auto j:v[i]){
nd[j]=i;
}
vall[i]=nd[arr[i]];
}
int l[n],r[n];
for(int i = 0;i<n;i++){
l[i]=i ,r[i] = i;
while(1){
if(l[i]&&valr[l[i]]<=r[i]){
r[i] = max(r[i],r[l[i]-1]);
l[i] = l[l[i]-1];
}else if(r[i]<n-1&&vall[r[i]]>=l[i]){
r[i]++;
}else break;
}
}
int q;cin>>q;
while(q--){
int x,y;
cin>>x>>y;
x--;y--;
if(y>=l[x]&&y<=r[x]){
cout<<"YES\n";
}
else cout<<"NO\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
552 KB |
Output is correct |
3 |
Correct |
3 ms |
852 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
552 KB |
Output is correct |
3 |
Correct |
3 ms |
852 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
464 KB |
Output is correct |
8 |
Correct |
86 ms |
6364 KB |
Output is correct |
9 |
Correct |
85 ms |
6300 KB |
Output is correct |
10 |
Correct |
90 ms |
6688 KB |
Output is correct |
11 |
Correct |
88 ms |
7272 KB |
Output is correct |
12 |
Correct |
78 ms |
5840 KB |
Output is correct |
13 |
Correct |
81 ms |
6564 KB |
Output is correct |
14 |
Correct |
83 ms |
6664 KB |
Output is correct |
15 |
Correct |
88 ms |
6476 KB |
Output is correct |
16 |
Correct |
81 ms |
6348 KB |
Output is correct |
17 |
Correct |
86 ms |
6452 KB |
Output is correct |
18 |
Correct |
84 ms |
6564 KB |
Output is correct |
19 |
Correct |
84 ms |
6596 KB |
Output is correct |
20 |
Correct |
84 ms |
6440 KB |
Output is correct |
21 |
Correct |
84 ms |
6348 KB |
Output is correct |
22 |
Correct |
85 ms |
6452 KB |
Output is correct |
23 |
Correct |
84 ms |
6340 KB |
Output is correct |
24 |
Correct |
93 ms |
6320 KB |
Output is correct |
25 |
Correct |
85 ms |
6244 KB |
Output is correct |
26 |
Correct |
83 ms |
6468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
200 ms |
17112 KB |
Output is correct |
2 |
Correct |
161 ms |
16984 KB |
Output is correct |
3 |
Correct |
163 ms |
16872 KB |
Output is correct |
4 |
Correct |
165 ms |
17092 KB |
Output is correct |
5 |
Correct |
159 ms |
17064 KB |
Output is correct |
6 |
Correct |
143 ms |
16392 KB |
Output is correct |
7 |
Correct |
128 ms |
16096 KB |
Output is correct |
8 |
Correct |
133 ms |
16100 KB |
Output is correct |
9 |
Correct |
143 ms |
16136 KB |
Output is correct |
10 |
Correct |
127 ms |
16188 KB |
Output is correct |
11 |
Correct |
136 ms |
16096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
460 KB |
Output is correct |
2 |
Correct |
3 ms |
552 KB |
Output is correct |
3 |
Correct |
3 ms |
852 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
2 ms |
464 KB |
Output is correct |
8 |
Correct |
86 ms |
6364 KB |
Output is correct |
9 |
Correct |
85 ms |
6300 KB |
Output is correct |
10 |
Correct |
90 ms |
6688 KB |
Output is correct |
11 |
Correct |
88 ms |
7272 KB |
Output is correct |
12 |
Correct |
78 ms |
5840 KB |
Output is correct |
13 |
Correct |
81 ms |
6564 KB |
Output is correct |
14 |
Correct |
83 ms |
6664 KB |
Output is correct |
15 |
Correct |
88 ms |
6476 KB |
Output is correct |
16 |
Correct |
81 ms |
6348 KB |
Output is correct |
17 |
Correct |
86 ms |
6452 KB |
Output is correct |
18 |
Correct |
84 ms |
6564 KB |
Output is correct |
19 |
Correct |
84 ms |
6596 KB |
Output is correct |
20 |
Correct |
84 ms |
6440 KB |
Output is correct |
21 |
Correct |
84 ms |
6348 KB |
Output is correct |
22 |
Correct |
85 ms |
6452 KB |
Output is correct |
23 |
Correct |
84 ms |
6340 KB |
Output is correct |
24 |
Correct |
93 ms |
6320 KB |
Output is correct |
25 |
Correct |
85 ms |
6244 KB |
Output is correct |
26 |
Correct |
83 ms |
6468 KB |
Output is correct |
27 |
Correct |
200 ms |
17112 KB |
Output is correct |
28 |
Correct |
161 ms |
16984 KB |
Output is correct |
29 |
Correct |
163 ms |
16872 KB |
Output is correct |
30 |
Correct |
165 ms |
17092 KB |
Output is correct |
31 |
Correct |
159 ms |
17064 KB |
Output is correct |
32 |
Correct |
143 ms |
16392 KB |
Output is correct |
33 |
Correct |
128 ms |
16096 KB |
Output is correct |
34 |
Correct |
133 ms |
16100 KB |
Output is correct |
35 |
Correct |
143 ms |
16136 KB |
Output is correct |
36 |
Correct |
127 ms |
16188 KB |
Output is correct |
37 |
Correct |
136 ms |
16096 KB |
Output is correct |
38 |
Correct |
249 ms |
44716 KB |
Output is correct |
39 |
Correct |
315 ms |
52404 KB |
Output is correct |
40 |
Correct |
226 ms |
35956 KB |
Output is correct |
41 |
Correct |
281 ms |
50720 KB |
Output is correct |
42 |
Correct |
137 ms |
17328 KB |
Output is correct |
43 |
Correct |
161 ms |
17340 KB |
Output is correct |
44 |
Correct |
184 ms |
27824 KB |
Output is correct |
45 |
Correct |
182 ms |
27972 KB |
Output is correct |
46 |
Correct |
201 ms |
28140 KB |
Output is correct |
47 |
Correct |
131 ms |
17308 KB |
Output is correct |
48 |
Correct |
153 ms |
17088 KB |
Output is correct |
49 |
Correct |
205 ms |
27748 KB |
Output is correct |
50 |
Correct |
223 ms |
27860 KB |
Output is correct |
51 |
Correct |
200 ms |
28076 KB |
Output is correct |
52 |
Correct |
200 ms |
26708 KB |
Output is correct |
53 |
Correct |
233 ms |
36344 KB |
Output is correct |
54 |
Correct |
299 ms |
45612 KB |
Output is correct |
55 |
Correct |
257 ms |
36396 KB |
Output is correct |