This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author: wxhtzdy
* created: 16.09.2023 20:57:23
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> c(n);
for (int i = 0; i + 1 < n; i++) {
cin >> c[i];
--c[i];
}
vector<set<int>> pos(n);
for (int i = 0; i < n; i++) {
int k;
cin >> k;
for (int j = 0; j < k; j++) {
int a;
cin >> a;
--a;
pos[a].insert(i);
}
}
auto Have = [&](int L, int R, int k) {
auto it = pos[k].lower_bound(L);
return (it != pos[k].end() && *it <= R);
};
vector<int> L(n), R(n);
for (int i = 0; i < n; i++) {
L[i] = R[i] = i;
while (true) {
if (L[i] > 0 && Have(L[i], R[i], c[L[i] - 1])) {
L[i] = L[L[i] - 1];
R[i] = max(R[i], R[L[i]]);
} else if (R[i] + 1 < n && Have(L[i], R[i], c[R[i]])) {
R[i] += 1;
} else {
break;
}
}
}
int q;
cin >> q;
while (q--) {
int x, y;
cin >> x >> y;
--x; --y;
cout << (L[x] <= y && y <= R[x] ? "YES" : "NO") << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |