This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<long long,long long>pii;
typedef pair<int,pii>pi2;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
void solve(){
int n;
cin >> n;
int arr[n+1];
for(int x=1;x<n;x++){
cin >> arr[x];
}
vector<int>storage[n+5];
int temp,temp2;
for(int x=1;x<=n;x++){
cin >> temp;
for(int y=0;y<temp;y++){
cin >> temp2;
storage[x].push_back(temp2);
}
}
pii ans[n+5];
for(int x=1;x<=n;x++){
int l=x;
int r=x;
set<int>se;
for(auto it:storage[x]) se.insert(it);
while(1){
if(l!=1&&se.find(arr[l-1])!=se.end()){
l--;
for(auto it:storage[l]) se.insert(it);
}
else if(r!=n&&se.find(arr[r])!=se.end()){
r++;
for(auto it:storage[r]) se.insert(it);
}
else break;
}
ans[x]={l,r};
}
int q;
cin >> q;
for(int x=0;x<q;x++){
cin >> temp >> temp2;
if(ans[temp].first<=temp2&&ans[temp].second>=temp2){
cout << "YES\n";
}
else cout << "NO\n";
}
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//freopen("in.txt","r",stdin);
//cin >> t;
while(t--){
solve();
}
}
# | 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... |