이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define lb lower_bound
#define gibon ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long long ll;
using namespace std;
const int mxN=500030;
const int mxM=500004;
const int MOD=998244353;
const ll INF=8e18;
int N, Q;
vector <int> key[mxN];
vector <int> kpos[mxN];
int C[mxN];
int l[mxN], r[mxN];
int kp[mxN];
pii qry[mxN];
pii rng[mxN];
void input(){
cin >> N;
for(int i=1;i<N;i++) cin >> C[i];
for(int i=1;i<=N;i++){
int a;
cin >> a;
while(a--){
int b;
cin >> b;
key[i].push_back(b);
}
}
cin >> Q;
for(int i=1;i<=Q;i++){
cin >> qry[i].fi >> qry[i].se;
}
}
void make_lr(){
for(int i=1;i<=N;i++){
for(int x : key[i]) kp[x]=i;
if(i==N) break;
l[i]=kp[C[i]];
}
for(int i=1;i<=N;i++) kp[i]=N+1;
for(int i=N;i>=1;i--){
for(int x : key[i]) kp[x]=i;
if(i==1) break;
r[i-1]=kp[C[i-1]];
}
}
void f(int now){
int s=now, e=now;
while(true){
if(s!=1 && r[s-1]<=e){
s--;
s=min(s, rng[s].fi);
e=max(e, rng[s].se);
continue;
}
if(e!=N && l[e]>=s){
e++;
s=min(s, rng[e].fi);
e=max(e, rng[e].se);
continue;
}
break;
}
rng[now]=pii(s, e);
}
int main()
{
gibon
input();
make_lr();
for(int i=1;i<=N;i++) rng[i]=pii(i, i);
int M=sqrt(N);
for(int i=0;i<M;i++){
int s=N;
while(s%M!=i) s--;
for(;s>=1;s-=M){
f(s);
}
}
for(int i=1;i<=Q;i++)
{
auto [a, b]=qry[i];
if(b<rng[a].fi || b>rng[a].se) cout << "NO\n";
else cout << "YES\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... |