#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5.1e5;
int N;
int C[MAXN];
vector<int> A[MAXN];
int last[MAXN];
int prv[MAXN]; // previous position with corresponding key
int nxt[MAXN]; // next
int lo[MAXN];
int hi[MAXN];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> N;
for (int i = 1; i <= N-1; i++) {
cin >> C[i];
}
for (int i = 1; i <= N; i++) {
int B; cin >> B;
A[i].reserve(B);
for (int j = 0; j < B; j++) {
int v; cin >> v;
A[i].push_back(v);
}
}
for (int i = 1; i <= N-1; i++) {
for (int v : A[i]) {
last[v] = i;
}
prv[i] = last[C[i]];
}
fill(last + 1, last + N + 1, N+1);
for (int i = N; i >= 2; i--) {
for (int v : A[i]) {
last[v] = i;
}
nxt[i-1] = last[C[i-1]];
}
for (int i = 1; i <= N; i++) {
int l = i;
int r = i;
while (true) {
if (l > 1 && nxt[l-1] <= r) {
r = max(r, hi[l-1]);
l = lo[l-1];
continue;
}
if (r+1 <= N && prv[r] >= l) {
r++;
continue;
}
break;
}
lo[i] = l;
hi[i] = r;
}
int Q; cin >> Q;
while (Q--) {
int x, y; cin >> x >> y;
if (lo[x] <= y && y <= hi[x]) {
cout << "YES" << '\n';
} else {
cout << "NO" << '\n';
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
12544 KB |
Output is correct |
2 |
Correct |
11 ms |
12672 KB |
Output is correct |
3 |
Correct |
11 ms |
12800 KB |
Output is correct |
4 |
Correct |
10 ms |
12544 KB |
Output is correct |
5 |
Correct |
10 ms |
12544 KB |
Output is correct |
6 |
Correct |
10 ms |
12544 KB |
Output is correct |
7 |
Correct |
10 ms |
12544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
12544 KB |
Output is correct |
2 |
Correct |
11 ms |
12672 KB |
Output is correct |
3 |
Correct |
11 ms |
12800 KB |
Output is correct |
4 |
Correct |
10 ms |
12544 KB |
Output is correct |
5 |
Correct |
10 ms |
12544 KB |
Output is correct |
6 |
Correct |
10 ms |
12544 KB |
Output is correct |
7 |
Correct |
10 ms |
12544 KB |
Output is correct |
8 |
Correct |
133 ms |
18424 KB |
Output is correct |
9 |
Correct |
132 ms |
18296 KB |
Output is correct |
10 |
Correct |
133 ms |
18680 KB |
Output is correct |
11 |
Correct |
139 ms |
19160 KB |
Output is correct |
12 |
Correct |
121 ms |
17912 KB |
Output is correct |
13 |
Correct |
127 ms |
18552 KB |
Output is correct |
14 |
Correct |
131 ms |
18552 KB |
Output is correct |
15 |
Correct |
129 ms |
18552 KB |
Output is correct |
16 |
Correct |
127 ms |
18424 KB |
Output is correct |
17 |
Correct |
128 ms |
18708 KB |
Output is correct |
18 |
Correct |
133 ms |
18708 KB |
Output is correct |
19 |
Correct |
129 ms |
18552 KB |
Output is correct |
20 |
Correct |
125 ms |
18552 KB |
Output is correct |
21 |
Correct |
129 ms |
18456 KB |
Output is correct |
22 |
Correct |
127 ms |
18480 KB |
Output is correct |
23 |
Correct |
132 ms |
18296 KB |
Output is correct |
24 |
Correct |
131 ms |
18296 KB |
Output is correct |
25 |
Correct |
130 ms |
18296 KB |
Output is correct |
26 |
Correct |
135 ms |
18296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
207 ms |
26872 KB |
Output is correct |
2 |
Correct |
201 ms |
26744 KB |
Output is correct |
3 |
Correct |
194 ms |
26616 KB |
Output is correct |
4 |
Correct |
197 ms |
26872 KB |
Output is correct |
5 |
Correct |
199 ms |
26872 KB |
Output is correct |
6 |
Correct |
178 ms |
26232 KB |
Output is correct |
7 |
Correct |
173 ms |
25848 KB |
Output is correct |
8 |
Correct |
172 ms |
25848 KB |
Output is correct |
9 |
Correct |
177 ms |
25976 KB |
Output is correct |
10 |
Correct |
173 ms |
25848 KB |
Output is correct |
11 |
Correct |
175 ms |
25848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
12544 KB |
Output is correct |
2 |
Correct |
11 ms |
12672 KB |
Output is correct |
3 |
Correct |
11 ms |
12800 KB |
Output is correct |
4 |
Correct |
10 ms |
12544 KB |
Output is correct |
5 |
Correct |
10 ms |
12544 KB |
Output is correct |
6 |
Correct |
10 ms |
12544 KB |
Output is correct |
7 |
Correct |
10 ms |
12544 KB |
Output is correct |
8 |
Correct |
133 ms |
18424 KB |
Output is correct |
9 |
Correct |
132 ms |
18296 KB |
Output is correct |
10 |
Correct |
133 ms |
18680 KB |
Output is correct |
11 |
Correct |
139 ms |
19160 KB |
Output is correct |
12 |
Correct |
121 ms |
17912 KB |
Output is correct |
13 |
Correct |
127 ms |
18552 KB |
Output is correct |
14 |
Correct |
131 ms |
18552 KB |
Output is correct |
15 |
Correct |
129 ms |
18552 KB |
Output is correct |
16 |
Correct |
127 ms |
18424 KB |
Output is correct |
17 |
Correct |
128 ms |
18708 KB |
Output is correct |
18 |
Correct |
133 ms |
18708 KB |
Output is correct |
19 |
Correct |
129 ms |
18552 KB |
Output is correct |
20 |
Correct |
125 ms |
18552 KB |
Output is correct |
21 |
Correct |
129 ms |
18456 KB |
Output is correct |
22 |
Correct |
127 ms |
18480 KB |
Output is correct |
23 |
Correct |
132 ms |
18296 KB |
Output is correct |
24 |
Correct |
131 ms |
18296 KB |
Output is correct |
25 |
Correct |
130 ms |
18296 KB |
Output is correct |
26 |
Correct |
135 ms |
18296 KB |
Output is correct |
27 |
Correct |
207 ms |
26872 KB |
Output is correct |
28 |
Correct |
201 ms |
26744 KB |
Output is correct |
29 |
Correct |
194 ms |
26616 KB |
Output is correct |
30 |
Correct |
197 ms |
26872 KB |
Output is correct |
31 |
Correct |
199 ms |
26872 KB |
Output is correct |
32 |
Correct |
178 ms |
26232 KB |
Output is correct |
33 |
Correct |
173 ms |
25848 KB |
Output is correct |
34 |
Correct |
172 ms |
25848 KB |
Output is correct |
35 |
Correct |
177 ms |
25976 KB |
Output is correct |
36 |
Correct |
173 ms |
25848 KB |
Output is correct |
37 |
Correct |
175 ms |
25848 KB |
Output is correct |
38 |
Correct |
312 ms |
47476 KB |
Output is correct |
39 |
Correct |
325 ms |
52728 KB |
Output is correct |
40 |
Correct |
296 ms |
40884 KB |
Output is correct |
41 |
Correct |
313 ms |
51064 KB |
Output is correct |
42 |
Correct |
179 ms |
27000 KB |
Output is correct |
43 |
Correct |
180 ms |
27128 KB |
Output is correct |
44 |
Correct |
232 ms |
35192 KB |
Output is correct |
45 |
Correct |
239 ms |
35448 KB |
Output is correct |
46 |
Correct |
244 ms |
35448 KB |
Output is correct |
47 |
Correct |
182 ms |
27128 KB |
Output is correct |
48 |
Correct |
184 ms |
26852 KB |
Output is correct |
49 |
Correct |
239 ms |
35192 KB |
Output is correct |
50 |
Correct |
239 ms |
35192 KB |
Output is correct |
51 |
Correct |
239 ms |
35576 KB |
Output is correct |
52 |
Correct |
229 ms |
34040 KB |
Output is correct |
53 |
Correct |
276 ms |
41208 KB |
Output is correct |
54 |
Correct |
308 ms |
48504 KB |
Output is correct |
55 |
Correct |
271 ms |
41336 KB |
Output is correct |