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 dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
const int N=5e5+99;
int n,t,q,a[N],L[N],R[N],col[N];
vector<int> v[N];
void solve(int x){
L[x]=R[x]=x;
while(1){
int b=0;
if(1<L[x] && lower_bound(all(v[col[L[x]-1]]),L[x])!=upper_bound(all(v[col[L[x]-1]]),R[x])){
int u=L[x]-1;
L[x]=u;
if(L[u]>0){
minm(L[x],L[u]);
}
if(R[u]>0){
maxm(R[x],R[u]);
}
b=1;
}
if(R[x]<n && lower_bound(all(v[col[R[x]]]),L[x])!=upper_bound(all(v[col[R[x]]]),R[x])){
int u=R[x]+1;
R[x]=u;
if(L[u]>0){
minm(L[x],L[u]);
}
if(R[u]>0){
maxm(R[x],R[u]);
}
b=1;
}
if(!b) break;
}
//cout<<x<<" "<<L[x]<<" "<<R[x]<<endl;
}
int main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
srand(time(NULL));
cin>>n;
f(i,1,n) cin>>col[i];
f(i,1,n+1){
int k,x;
cin>>k;
f(j,0,k){
cin>>x;
v[x].pb(i);
}
}
vector<int> vec(n);
iota(all(vec),1);
random_shuffle(all(vec));
for(auto x : vec){
solve(x);
}
cin>>q;
f(i,0,q){
int u,v;
cin>>u>>v;
if(L[u]<=v && v<=R[u]){
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... |