#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()
const ll N=5e5+5;
ll n,c[N],b[N],l[N],r[N],last[N],p[N],q[N];
vector<ll>key[N];
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n;
for(ll i=1;i<n;i++){
cin>>c[i];
}
for(ll i=1;i<=n;i++){
cin>>b[i];
key[i].resize(b[i]);
for(auto &k:key[i]){
cin>>k;
}
}
fill(last,last+n+1,0);
//left closest position
for(ll i=1;i<n;i++){
for(ll k:key[i]){
last[k]=i;
}
p[i]=last[c[i]];
}
fill(last,last+n+1,n+1);
//right closest position
for(ll i=n;i>=2;i--){
for(ll k:key[i]){
last[k]=i;
}
q[i]=last[c[i-1]];
}
for(ll i=1;i<=n;i++){
l[i]=i;
r[i]=i;
while(true){
if(l[i]>1&&q[l[i]]<=r[i]){//can move to left
l[i]--;
if(r[l[i]]>=i){
r[i]=r[l[i]];
l[i]=l[l[i]];
break;
}
}
else if(r[i]<n&&p[r[i]]>=l[i]){
r[i]++;
}
else{
break;
}
}
}
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 |
1 |
Correct |
6 ms |
25260 KB |
Output is correct |
2 |
Correct |
5 ms |
25424 KB |
Output is correct |
3 |
Correct |
6 ms |
25472 KB |
Output is correct |
4 |
Correct |
7 ms |
25424 KB |
Output is correct |
5 |
Correct |
5 ms |
25212 KB |
Output is correct |
6 |
Correct |
5 ms |
25424 KB |
Output is correct |
7 |
Correct |
5 ms |
25196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
25260 KB |
Output is correct |
2 |
Correct |
5 ms |
25424 KB |
Output is correct |
3 |
Correct |
6 ms |
25472 KB |
Output is correct |
4 |
Correct |
7 ms |
25424 KB |
Output is correct |
5 |
Correct |
5 ms |
25212 KB |
Output is correct |
6 |
Correct |
5 ms |
25424 KB |
Output is correct |
7 |
Correct |
5 ms |
25196 KB |
Output is correct |
8 |
Correct |
62 ms |
31136 KB |
Output is correct |
9 |
Correct |
65 ms |
31132 KB |
Output is correct |
10 |
Correct |
64 ms |
31560 KB |
Output is correct |
11 |
Correct |
74 ms |
31816 KB |
Output is correct |
12 |
Correct |
59 ms |
30792 KB |
Output is correct |
13 |
Correct |
61 ms |
31304 KB |
Output is correct |
14 |
Correct |
62 ms |
31304 KB |
Output is correct |
15 |
Correct |
59 ms |
31272 KB |
Output is correct |
16 |
Correct |
54 ms |
31052 KB |
Output is correct |
17 |
Correct |
59 ms |
31308 KB |
Output is correct |
18 |
Correct |
60 ms |
31304 KB |
Output is correct |
19 |
Correct |
87 ms |
31264 KB |
Output is correct |
20 |
Correct |
59 ms |
31304 KB |
Output is correct |
21 |
Correct |
60 ms |
31048 KB |
Output is correct |
22 |
Correct |
59 ms |
31304 KB |
Output is correct |
23 |
Correct |
86 ms |
31196 KB |
Output is correct |
24 |
Correct |
63 ms |
31060 KB |
Output is correct |
25 |
Correct |
62 ms |
31048 KB |
Output is correct |
26 |
Correct |
61 ms |
31048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
40712 KB |
Output is correct |
2 |
Correct |
106 ms |
40528 KB |
Output is correct |
3 |
Correct |
105 ms |
40144 KB |
Output is correct |
4 |
Correct |
113 ms |
40780 KB |
Output is correct |
5 |
Correct |
100 ms |
40524 KB |
Output is correct |
6 |
Correct |
82 ms |
38732 KB |
Output is correct |
7 |
Correct |
96 ms |
38476 KB |
Output is correct |
8 |
Correct |
95 ms |
38324 KB |
Output is correct |
9 |
Correct |
88 ms |
38424 KB |
Output is correct |
10 |
Correct |
87 ms |
38476 KB |
Output is correct |
11 |
Correct |
83 ms |
38368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
25260 KB |
Output is correct |
2 |
Correct |
5 ms |
25424 KB |
Output is correct |
3 |
Correct |
6 ms |
25472 KB |
Output is correct |
4 |
Correct |
7 ms |
25424 KB |
Output is correct |
5 |
Correct |
5 ms |
25212 KB |
Output is correct |
6 |
Correct |
5 ms |
25424 KB |
Output is correct |
7 |
Correct |
5 ms |
25196 KB |
Output is correct |
8 |
Correct |
62 ms |
31136 KB |
Output is correct |
9 |
Correct |
65 ms |
31132 KB |
Output is correct |
10 |
Correct |
64 ms |
31560 KB |
Output is correct |
11 |
Correct |
74 ms |
31816 KB |
Output is correct |
12 |
Correct |
59 ms |
30792 KB |
Output is correct |
13 |
Correct |
61 ms |
31304 KB |
Output is correct |
14 |
Correct |
62 ms |
31304 KB |
Output is correct |
15 |
Correct |
59 ms |
31272 KB |
Output is correct |
16 |
Correct |
54 ms |
31052 KB |
Output is correct |
17 |
Correct |
59 ms |
31308 KB |
Output is correct |
18 |
Correct |
60 ms |
31304 KB |
Output is correct |
19 |
Correct |
87 ms |
31264 KB |
Output is correct |
20 |
Correct |
59 ms |
31304 KB |
Output is correct |
21 |
Correct |
60 ms |
31048 KB |
Output is correct |
22 |
Correct |
59 ms |
31304 KB |
Output is correct |
23 |
Correct |
86 ms |
31196 KB |
Output is correct |
24 |
Correct |
63 ms |
31060 KB |
Output is correct |
25 |
Correct |
62 ms |
31048 KB |
Output is correct |
26 |
Correct |
61 ms |
31048 KB |
Output is correct |
27 |
Correct |
125 ms |
40712 KB |
Output is correct |
28 |
Correct |
106 ms |
40528 KB |
Output is correct |
29 |
Correct |
105 ms |
40144 KB |
Output is correct |
30 |
Correct |
113 ms |
40780 KB |
Output is correct |
31 |
Correct |
100 ms |
40524 KB |
Output is correct |
32 |
Correct |
82 ms |
38732 KB |
Output is correct |
33 |
Correct |
96 ms |
38476 KB |
Output is correct |
34 |
Correct |
95 ms |
38324 KB |
Output is correct |
35 |
Correct |
88 ms |
38424 KB |
Output is correct |
36 |
Correct |
87 ms |
38476 KB |
Output is correct |
37 |
Correct |
83 ms |
38368 KB |
Output is correct |
38 |
Correct |
174 ms |
64332 KB |
Output is correct |
39 |
Correct |
183 ms |
68180 KB |
Output is correct |
40 |
Correct |
151 ms |
59468 KB |
Output is correct |
41 |
Correct |
166 ms |
66380 KB |
Output is correct |
42 |
Correct |
85 ms |
39500 KB |
Output is correct |
43 |
Correct |
97 ms |
39500 KB |
Output is correct |
44 |
Correct |
143 ms |
53520 KB |
Output is correct |
45 |
Correct |
114 ms |
53580 KB |
Output is correct |
46 |
Correct |
121 ms |
53836 KB |
Output is correct |
47 |
Correct |
88 ms |
39500 KB |
Output is correct |
48 |
Correct |
91 ms |
39456 KB |
Output is correct |
49 |
Correct |
121 ms |
53584 KB |
Output is correct |
50 |
Correct |
123 ms |
53580 KB |
Output is correct |
51 |
Correct |
123 ms |
53896 KB |
Output is correct |
52 |
Correct |
142 ms |
52556 KB |
Output is correct |
53 |
Correct |
140 ms |
59724 KB |
Output is correct |
54 |
Correct |
158 ms |
65356 KB |
Output is correct |
55 |
Correct |
132 ms |
59916 KB |
Output is correct |