이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n;
cin>>n;
ll c[n+5];
for(ll i=1;i<n;i++){
cin>>c[i];
}
ll b[n+5];
vector<vector<ll>>key(n+5);
for(ll i=1;i<=n;i++){
cin>>b[i];
key[i].resize(b[i]);
for(ll j=0;j<b[i];j++){
cin>>key[i][j];
}
}
vector<bool>have(n+1,0);
auto add=[&](ll x) ->void{
for(ll k:key[x]){
have[k]=true;
}
};
ll L[n+5],R[n+5];
for(ll i=1;i<=n;i++){
ll l=i,r=i;
fill(all(have),0);
add(i);
while(l>1||r<n){
if(l>1&&have[c[l-1]]){
l--;
add(l);
}
else if(r<n&&have[c[r]]){
r++;
add(r);
}
else{
break;
}
}
L[i]=l;
R[i]=r;
}
ll q;
cin>>q;
while(q--){
ll x,y;
cin>>x>>y;
if(L[x]<=y&&y<=R[x]){
cout<<"YES\n";
}
else{
cout<<"NO\n";
}
}
}
# | 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... |