#include <bits/stdc++.h>
#define FR(i, N) for (int i = 0; i < int(N); i++)
using namespace std;
using ll = long long;
const int MAXN = (int)(5e5) + 5;
int maxright[MAXN];
int to[MAXN];
int last[MAXN];
vector<int> has[MAXN];
pair<int, int> interval[MAXN];
bool cont(int l, int r, int k) {
if (has[k].size() == 0 || has[k][0] > r || has[k].back() < l || k < 0) {
return false;
}
else {
int low = 0;
int high = has[k].size()-1;
while (low < high) {
int mid = (low + high)/2;
if (has[k][mid] >= l) {
high = mid;
}
else {
low = mid+1;
}
}
int sh = high;
low = 0; high = has[k].size()-1;
while (low < high) {
int mid = (low + high+1)/2;
if (has[k][mid] <= r) {
low = mid;
}
else {
high = mid-1;
}
}
return (low - sh + 1) > 0;
}
}
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int N, Q;
cin >> N;
to[N] = -1;
FR(i, N-1) {
cin >> to[i];
to[i]--;
}
FR(i, N) {
int B;
cin >> B;
FR(j, B) {
int a;
cin >> a;
a--;
has[a].push_back(i);
}
}
// maxright[N-1] = N-1;
// for (int i = N-2; i >= 0; i--) {
// int u = i;
// while (cont(i, u, to[u])) {
// u = maxright[u+1];
// }
// maxright[i] = u;
// }
for (int i = 0; i < N; i++) {
int l = i;
int r = i;
while (true) {
if (l != 0 && cont(l, r, to[l-1])) {
l = interval[l-1].first;
r = max(r, interval[l+1].second);
}
else if (r != N-1 && cont(l, r, to[r])) {
r++;
}
else {
break;
}
}
interval[i] = {l, r};
}
cin >> Q;
FR(i, Q) {
int x, y;
cin >> x >> y;
x--, y--;
if (interval[x].first <= y && y <= interval[x].second) {
cout << "YES" << '\n';
}
else cout << "NO" << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
12268 KB |
Output is correct |
2 |
Correct |
101 ms |
12268 KB |
Output is correct |
3 |
Correct |
13 ms |
12268 KB |
Output is correct |
4 |
Correct |
11 ms |
12268 KB |
Output is correct |
5 |
Correct |
11 ms |
12268 KB |
Output is correct |
6 |
Correct |
17 ms |
12268 KB |
Output is correct |
7 |
Correct |
16 ms |
12416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
12268 KB |
Output is correct |
2 |
Correct |
101 ms |
12268 KB |
Output is correct |
3 |
Correct |
13 ms |
12268 KB |
Output is correct |
4 |
Correct |
11 ms |
12268 KB |
Output is correct |
5 |
Correct |
11 ms |
12268 KB |
Output is correct |
6 |
Correct |
17 ms |
12268 KB |
Output is correct |
7 |
Correct |
16 ms |
12416 KB |
Output is correct |
8 |
Correct |
175 ms |
18028 KB |
Output is correct |
9 |
Correct |
142 ms |
18028 KB |
Output is correct |
10 |
Correct |
139 ms |
18412 KB |
Output is correct |
11 |
Correct |
158 ms |
18692 KB |
Output is correct |
12 |
Correct |
132 ms |
17772 KB |
Output is correct |
13 |
Correct |
137 ms |
18284 KB |
Output is correct |
14 |
Correct |
140 ms |
18412 KB |
Output is correct |
15 |
Correct |
173 ms |
18284 KB |
Output is correct |
16 |
Correct |
131 ms |
18028 KB |
Output is correct |
17 |
Correct |
139 ms |
18284 KB |
Output is correct |
18 |
Correct |
136 ms |
18372 KB |
Output is correct |
19 |
Correct |
141 ms |
18424 KB |
Output is correct |
20 |
Correct |
132 ms |
18360 KB |
Output is correct |
21 |
Correct |
129 ms |
18028 KB |
Output is correct |
22 |
Correct |
147 ms |
18156 KB |
Output is correct |
23 |
Correct |
141 ms |
18028 KB |
Output is correct |
24 |
Correct |
143 ms |
18028 KB |
Output is correct |
25 |
Correct |
142 ms |
18028 KB |
Output is correct |
26 |
Correct |
142 ms |
18028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3062 ms |
17012 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
12268 KB |
Output is correct |
2 |
Correct |
101 ms |
12268 KB |
Output is correct |
3 |
Correct |
13 ms |
12268 KB |
Output is correct |
4 |
Correct |
11 ms |
12268 KB |
Output is correct |
5 |
Correct |
11 ms |
12268 KB |
Output is correct |
6 |
Correct |
17 ms |
12268 KB |
Output is correct |
7 |
Correct |
16 ms |
12416 KB |
Output is correct |
8 |
Correct |
175 ms |
18028 KB |
Output is correct |
9 |
Correct |
142 ms |
18028 KB |
Output is correct |
10 |
Correct |
139 ms |
18412 KB |
Output is correct |
11 |
Correct |
158 ms |
18692 KB |
Output is correct |
12 |
Correct |
132 ms |
17772 KB |
Output is correct |
13 |
Correct |
137 ms |
18284 KB |
Output is correct |
14 |
Correct |
140 ms |
18412 KB |
Output is correct |
15 |
Correct |
173 ms |
18284 KB |
Output is correct |
16 |
Correct |
131 ms |
18028 KB |
Output is correct |
17 |
Correct |
139 ms |
18284 KB |
Output is correct |
18 |
Correct |
136 ms |
18372 KB |
Output is correct |
19 |
Correct |
141 ms |
18424 KB |
Output is correct |
20 |
Correct |
132 ms |
18360 KB |
Output is correct |
21 |
Correct |
129 ms |
18028 KB |
Output is correct |
22 |
Correct |
147 ms |
18156 KB |
Output is correct |
23 |
Correct |
141 ms |
18028 KB |
Output is correct |
24 |
Correct |
143 ms |
18028 KB |
Output is correct |
25 |
Correct |
142 ms |
18028 KB |
Output is correct |
26 |
Correct |
142 ms |
18028 KB |
Output is correct |
27 |
Execution timed out |
3062 ms |
17012 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |