#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 5e5 + 2;
const int inf = 1e9;
int c[N], le[N], ri[N], l[N], r[N], lst[N];
vector<int> b[N];
bool Between(int L, int R, int x) {
return L <= x && x <= R;
}
bool Can(int L, int R, int x) {
return Between(L, R, le[x]) || Between(L, R, ri[x]);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n; cin >> n;
for (int i = 1; i < n; i++) cin >> c[i];
for (int i = 1; i <= n; i++) {
int sz; cin >> sz;
b[i].resize(sz);
for (int j = 0; j < sz; j++) cin >> b[i][j];
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < b[i][j].size(); j++) lst[j] = i;
le[i] = lst[c[i]];
}
for (int i = 1; i <= n; i++) lst[i] = 0;
for (int i = n; i > 1; i--) {
for (int j = 0; j < b[i][j].size(); j++) lst[j] = i;
ri[i - 1] = lst[c[i - 1]];
}
for (int i = 1; i <= n; i++) {
l[i] = r[i] = i;
while (1) {
if (l[i] > 1 && Can(l[i], r[i], l[i] - 1)) {
l[i] = l[l[i] - 1];
smax(r[i], r[l[i]]);
}
else if (r[i] < n && Can(l[i], r[i], r[i])) r[i]++;
else break;
}
}
int q; cin >> q;
while (q--) {
int x, y;
cin >> x >> y;
if (Between(l[x], r[x], y)) cout << "YES" << en;
else cout << "NO" << en;
}
return 0;
}
Compilation message
long_mansion.cpp: In function 'int main()':
long_mansion.cpp:31:37: error: request for member 'size' in 'b[i].std::vector<int>::operator[](((std::vector<int>::size_type)j))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
31 | for (int j = 0; j < b[i][j].size(); j++) lst[j] = i;
| ^~~~
long_mansion.cpp:36:37: error: request for member 'size' in 'b[i].std::vector<int>::operator[](((std::vector<int>::size_type)j))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
36 | for (int j = 0; j < b[i][j].size(); j++) lst[j] = i;
| ^~~~