#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define ii pair<int,int>
#define ve vector
#define all(x) x.begin(), x.end()
#define fo(i,a,b) for (int i=(a),_b=(b); i<=_b; ++i)
#define fd(i,a,b) for (int i=(a),_b=(b); i>=_b; --i)
#define maxi(a, b) a = max(a, b)
#define mini(a, b) a = min(a, b)
#define _ << ' ' <<
const int N = 1e6+5, inf = 1e9+10, mod = 1e9+7;
/**
**/
bool MBE;
int l[N], r[N], c[N], n, q;
ve<int> pos[N];
bool bin(int l, int r, int x) {
auto p=lower_bound(all(pos[x]),l);
if (p==pos[x].end() || *p > r) return 0;
return 1;
}
void sol() {
cin >> n;
fo(i,1,n-1) cin >> c[i];
fo(i,1,n) {
int sz, x; cin >> sz;
while (sz--) {
cin >> x;
pos[x].pb(i);
}
}
fo(i,1,n) {
l[i]=r[i]=i;
while (1) {
if (l[i]>1&&bin(l[i],r[i],c[l[i]-1]))
mini(l[i],l[i-1]);
else if (r[i]<n&&bin(l[i],r[i],c[r[i]]))
r[i]++;
else break;
}
}
cin >> q;
while (q--) {
int x, y; cin >> x >> y;
cout << (l[x] <= y && y <= r[x] ? "YES\n" : "NO\n");
}
}
bool MED;
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
if(fopen("A.inp","r")) {
freopen("A.inp","r",stdin);
freopen("A.out","w",stdout);
}
int tc = 1; // cin >> tc;
fo(i,1,tc) sol();
// cerr << "MEM = " << abs(&MED-&MBE)/1024.0/1024.0 << " MB";
return 0;
}
Compilation message (stderr)
long_mansion.cpp: In function 'int main()':
long_mansion.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | freopen("A.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
long_mansion.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | freopen("A.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~| # | 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... |