#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)5e5 + 9;
int L[N];
int R[N];
int C[N];
vector<int> ls[N];
int las[N];
int lf[N];
int rf[N];
int main(){
fastIO;
int n;
cin >> n;
for(int i = 1; i < n; i ++ ){
cin >> C[i];
}
int x, k;
for(int i = 1; i <= n ; i ++ ){
cin >> k;
for(int j = 0 ; j < k ; j ++ ){
cin >> x;
ls[i].push_back(x);
}
}
for(int j = 1; j <= n; j ++ )
las[j] = -1;
for(int i = 1; i < n; i ++ ){
for(auto p : ls[i])
las[p] = i;
lf[i + 1] = las[C[i]];
}
for(int j = 1; j <= n; j ++ )
las[j] = -1;
for(int i = n; i > 1; i -- ){
for(auto p : ls[i])
las[p] = i;
rf[i - 1] = las[C[i - 1]];
}
for(int i = 1; i <= n; i ++ ){
L[i] = i;
R[i] = i;
while(1){
if(L[i] != 1 && rf[L[i] - 1] <= R[i] && rf[L[i] - 1] != -1){
R[i] = max(R[i], R[L[i]-1]);
L[i] = min(L[i], L[L[i]-1]);
}
else if(R[i] != n && lf[R[i] + 1] >= L[i] && lf[R[i] + 1] != -1){
R[i] ++ ;
}
else{
break;
}
}
}
int Q;
cin >> Q;
int p, q;
for(int i = 0 ; i < Q; i ++ ){
cin >> p >> q;
if(q >= L[p] && q <= R[p])
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
12284 KB |
Output is correct |
2 |
Correct |
17 ms |
12280 KB |
Output is correct |
3 |
Correct |
17 ms |
12408 KB |
Output is correct |
4 |
Correct |
17 ms |
12280 KB |
Output is correct |
5 |
Correct |
17 ms |
12280 KB |
Output is correct |
6 |
Correct |
17 ms |
12280 KB |
Output is correct |
7 |
Correct |
16 ms |
12280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
12284 KB |
Output is correct |
2 |
Correct |
17 ms |
12280 KB |
Output is correct |
3 |
Correct |
17 ms |
12408 KB |
Output is correct |
4 |
Correct |
17 ms |
12280 KB |
Output is correct |
5 |
Correct |
17 ms |
12280 KB |
Output is correct |
6 |
Correct |
17 ms |
12280 KB |
Output is correct |
7 |
Correct |
16 ms |
12280 KB |
Output is correct |
8 |
Correct |
133 ms |
13816 KB |
Output is correct |
9 |
Correct |
131 ms |
13712 KB |
Output is correct |
10 |
Correct |
143 ms |
14052 KB |
Output is correct |
11 |
Correct |
131 ms |
14200 KB |
Output is correct |
12 |
Correct |
125 ms |
13936 KB |
Output is correct |
13 |
Correct |
130 ms |
13984 KB |
Output is correct |
14 |
Correct |
145 ms |
13944 KB |
Output is correct |
15 |
Correct |
136 ms |
14076 KB |
Output is correct |
16 |
Correct |
131 ms |
14204 KB |
Output is correct |
17 |
Correct |
137 ms |
13944 KB |
Output is correct |
18 |
Correct |
133 ms |
13964 KB |
Output is correct |
19 |
Correct |
135 ms |
13996 KB |
Output is correct |
20 |
Correct |
129 ms |
14172 KB |
Output is correct |
21 |
Correct |
126 ms |
14292 KB |
Output is correct |
22 |
Correct |
132 ms |
14120 KB |
Output is correct |
23 |
Correct |
129 ms |
13816 KB |
Output is correct |
24 |
Correct |
146 ms |
13932 KB |
Output is correct |
25 |
Correct |
137 ms |
13880 KB |
Output is correct |
26 |
Correct |
134 ms |
13852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
239 ms |
19832 KB |
Output is correct |
2 |
Correct |
236 ms |
20020 KB |
Output is correct |
3 |
Correct |
238 ms |
25464 KB |
Output is correct |
4 |
Correct |
242 ms |
27128 KB |
Output is correct |
5 |
Correct |
245 ms |
27256 KB |
Output is correct |
6 |
Correct |
198 ms |
25976 KB |
Output is correct |
7 |
Correct |
200 ms |
25720 KB |
Output is correct |
8 |
Correct |
197 ms |
25592 KB |
Output is correct |
9 |
Correct |
207 ms |
25592 KB |
Output is correct |
10 |
Correct |
200 ms |
25784 KB |
Output is correct |
11 |
Correct |
209 ms |
25720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
12284 KB |
Output is correct |
2 |
Correct |
17 ms |
12280 KB |
Output is correct |
3 |
Correct |
17 ms |
12408 KB |
Output is correct |
4 |
Correct |
17 ms |
12280 KB |
Output is correct |
5 |
Correct |
17 ms |
12280 KB |
Output is correct |
6 |
Correct |
17 ms |
12280 KB |
Output is correct |
7 |
Correct |
16 ms |
12280 KB |
Output is correct |
8 |
Correct |
133 ms |
13816 KB |
Output is correct |
9 |
Correct |
131 ms |
13712 KB |
Output is correct |
10 |
Correct |
143 ms |
14052 KB |
Output is correct |
11 |
Correct |
131 ms |
14200 KB |
Output is correct |
12 |
Correct |
125 ms |
13936 KB |
Output is correct |
13 |
Correct |
130 ms |
13984 KB |
Output is correct |
14 |
Correct |
145 ms |
13944 KB |
Output is correct |
15 |
Correct |
136 ms |
14076 KB |
Output is correct |
16 |
Correct |
131 ms |
14204 KB |
Output is correct |
17 |
Correct |
137 ms |
13944 KB |
Output is correct |
18 |
Correct |
133 ms |
13964 KB |
Output is correct |
19 |
Correct |
135 ms |
13996 KB |
Output is correct |
20 |
Correct |
129 ms |
14172 KB |
Output is correct |
21 |
Correct |
126 ms |
14292 KB |
Output is correct |
22 |
Correct |
132 ms |
14120 KB |
Output is correct |
23 |
Correct |
129 ms |
13816 KB |
Output is correct |
24 |
Correct |
146 ms |
13932 KB |
Output is correct |
25 |
Correct |
137 ms |
13880 KB |
Output is correct |
26 |
Correct |
134 ms |
13852 KB |
Output is correct |
27 |
Correct |
239 ms |
19832 KB |
Output is correct |
28 |
Correct |
236 ms |
20020 KB |
Output is correct |
29 |
Correct |
238 ms |
25464 KB |
Output is correct |
30 |
Correct |
242 ms |
27128 KB |
Output is correct |
31 |
Correct |
245 ms |
27256 KB |
Output is correct |
32 |
Correct |
198 ms |
25976 KB |
Output is correct |
33 |
Correct |
200 ms |
25720 KB |
Output is correct |
34 |
Correct |
197 ms |
25592 KB |
Output is correct |
35 |
Correct |
207 ms |
25592 KB |
Output is correct |
36 |
Correct |
200 ms |
25784 KB |
Output is correct |
37 |
Correct |
209 ms |
25720 KB |
Output is correct |
38 |
Correct |
374 ms |
47232 KB |
Output is correct |
39 |
Correct |
386 ms |
52344 KB |
Output is correct |
40 |
Correct |
343 ms |
40824 KB |
Output is correct |
41 |
Correct |
363 ms |
50908 KB |
Output is correct |
42 |
Correct |
243 ms |
26824 KB |
Output is correct |
43 |
Correct |
206 ms |
26872 KB |
Output is correct |
44 |
Correct |
324 ms |
34980 KB |
Output is correct |
45 |
Correct |
300 ms |
35064 KB |
Output is correct |
46 |
Correct |
313 ms |
35268 KB |
Output is correct |
47 |
Correct |
218 ms |
26960 KB |
Output is correct |
48 |
Correct |
212 ms |
26588 KB |
Output is correct |
49 |
Correct |
283 ms |
34864 KB |
Output is correct |
50 |
Correct |
315 ms |
34892 KB |
Output is correct |
51 |
Correct |
299 ms |
35320 KB |
Output is correct |
52 |
Correct |
286 ms |
33792 KB |
Output is correct |
53 |
Correct |
324 ms |
41112 KB |
Output is correct |
54 |
Correct |
371 ms |
48056 KB |
Output is correct |
55 |
Correct |
327 ms |
41248 KB |
Output is correct |