#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define ET cout << "\n"
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
vector<int> v[500005];
int L[500005],R[500005],key[500005],ls[500005];
int rm[500005],relL[500005],relR[500005];
int main()
{jizz
int n,c,x,q,l,r;
cin >> n;
for(int i=1;i<n;++i)
cin >> key[i];
for(int i=1;i<=n;++i)
for(cin >> c;c--;)
cin >> x,v[i].pb(x);
for(int i=1;i<n;L[i]=ls[key[i]],++i)
for(int j:v[i])
ls[j]=i;
fill(ls+1,ls+n+1,n+1),R[0]=n+1;
for(int i=n-1;i>0;R[i]=ls[key[i]],--i)
for(int j:v[i+1])
ls[j]=i+1;
for(int i=n;i>0;--i)
for(rm[i]=i;L[rm[i]]>=i;rm[i]=rm[rm[i]+1]);
for(int i=1;i<=n;++i)
if(R[i-1]>rm[i])
relL[i]=i,relR[i]=rm[i];
else
for(relL[i]=relL[i-1],relR[i]=max(rm[i],relR[i-1]);L[relR[i]]>=relL[i]||R[relL[i]-1]<=relR[i];)
if(L[relR[i]]>=relL[i])
relR[i]=rm[relR[i]+1];
else if(R[relL[i]-1]<=relR[i])
relL[i]=relL[relL[i]-1],relR[i]=max(relR[i],relR[relL[i]]);
for(cin >> q;q--;)
if(cin >> l >> r,relL[l]<=r&&relR[l]>=r)
cout << "YES\n";
else
cout << "NO\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
12280 KB |
Output is correct |
2 |
Correct |
16 ms |
12408 KB |
Output is correct |
3 |
Correct |
19 ms |
12536 KB |
Output is correct |
4 |
Correct |
17 ms |
12280 KB |
Output is correct |
5 |
Correct |
16 ms |
12280 KB |
Output is correct |
6 |
Correct |
16 ms |
12280 KB |
Output is correct |
7 |
Correct |
16 ms |
12280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
12280 KB |
Output is correct |
2 |
Correct |
16 ms |
12408 KB |
Output is correct |
3 |
Correct |
19 ms |
12536 KB |
Output is correct |
4 |
Correct |
17 ms |
12280 KB |
Output is correct |
5 |
Correct |
16 ms |
12280 KB |
Output is correct |
6 |
Correct |
16 ms |
12280 KB |
Output is correct |
7 |
Correct |
16 ms |
12280 KB |
Output is correct |
8 |
Correct |
133 ms |
18256 KB |
Output is correct |
9 |
Correct |
133 ms |
18132 KB |
Output is correct |
10 |
Correct |
139 ms |
18524 KB |
Output is correct |
11 |
Correct |
144 ms |
18968 KB |
Output is correct |
12 |
Correct |
125 ms |
17808 KB |
Output is correct |
13 |
Correct |
131 ms |
18336 KB |
Output is correct |
14 |
Correct |
131 ms |
18320 KB |
Output is correct |
15 |
Correct |
131 ms |
18320 KB |
Output is correct |
16 |
Correct |
128 ms |
18160 KB |
Output is correct |
17 |
Correct |
133 ms |
18428 KB |
Output is correct |
18 |
Correct |
129 ms |
18532 KB |
Output is correct |
19 |
Correct |
132 ms |
18380 KB |
Output is correct |
20 |
Correct |
129 ms |
18284 KB |
Output is correct |
21 |
Correct |
128 ms |
18140 KB |
Output is correct |
22 |
Correct |
133 ms |
18212 KB |
Output is correct |
23 |
Correct |
130 ms |
18168 KB |
Output is correct |
24 |
Correct |
136 ms |
18172 KB |
Output is correct |
25 |
Correct |
130 ms |
18044 KB |
Output is correct |
26 |
Correct |
130 ms |
18168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
235 ms |
20344 KB |
Output is correct |
2 |
Correct |
228 ms |
27512 KB |
Output is correct |
3 |
Correct |
222 ms |
27256 KB |
Output is correct |
4 |
Correct |
234 ms |
27512 KB |
Output is correct |
5 |
Correct |
230 ms |
27512 KB |
Output is correct |
6 |
Correct |
202 ms |
26424 KB |
Output is correct |
7 |
Correct |
193 ms |
25976 KB |
Output is correct |
8 |
Correct |
197 ms |
26088 KB |
Output is correct |
9 |
Correct |
191 ms |
25976 KB |
Output is correct |
10 |
Correct |
193 ms |
26044 KB |
Output is correct |
11 |
Correct |
194 ms |
26016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
12280 KB |
Output is correct |
2 |
Correct |
16 ms |
12408 KB |
Output is correct |
3 |
Correct |
19 ms |
12536 KB |
Output is correct |
4 |
Correct |
17 ms |
12280 KB |
Output is correct |
5 |
Correct |
16 ms |
12280 KB |
Output is correct |
6 |
Correct |
16 ms |
12280 KB |
Output is correct |
7 |
Correct |
16 ms |
12280 KB |
Output is correct |
8 |
Correct |
133 ms |
18256 KB |
Output is correct |
9 |
Correct |
133 ms |
18132 KB |
Output is correct |
10 |
Correct |
139 ms |
18524 KB |
Output is correct |
11 |
Correct |
144 ms |
18968 KB |
Output is correct |
12 |
Correct |
125 ms |
17808 KB |
Output is correct |
13 |
Correct |
131 ms |
18336 KB |
Output is correct |
14 |
Correct |
131 ms |
18320 KB |
Output is correct |
15 |
Correct |
131 ms |
18320 KB |
Output is correct |
16 |
Correct |
128 ms |
18160 KB |
Output is correct |
17 |
Correct |
133 ms |
18428 KB |
Output is correct |
18 |
Correct |
129 ms |
18532 KB |
Output is correct |
19 |
Correct |
132 ms |
18380 KB |
Output is correct |
20 |
Correct |
129 ms |
18284 KB |
Output is correct |
21 |
Correct |
128 ms |
18140 KB |
Output is correct |
22 |
Correct |
133 ms |
18212 KB |
Output is correct |
23 |
Correct |
130 ms |
18168 KB |
Output is correct |
24 |
Correct |
136 ms |
18172 KB |
Output is correct |
25 |
Correct |
130 ms |
18044 KB |
Output is correct |
26 |
Correct |
130 ms |
18168 KB |
Output is correct |
27 |
Correct |
235 ms |
20344 KB |
Output is correct |
28 |
Correct |
228 ms |
27512 KB |
Output is correct |
29 |
Correct |
222 ms |
27256 KB |
Output is correct |
30 |
Correct |
234 ms |
27512 KB |
Output is correct |
31 |
Correct |
230 ms |
27512 KB |
Output is correct |
32 |
Correct |
202 ms |
26424 KB |
Output is correct |
33 |
Correct |
193 ms |
25976 KB |
Output is correct |
34 |
Correct |
197 ms |
26088 KB |
Output is correct |
35 |
Correct |
191 ms |
25976 KB |
Output is correct |
36 |
Correct |
193 ms |
26044 KB |
Output is correct |
37 |
Correct |
194 ms |
26016 KB |
Output is correct |
38 |
Correct |
357 ms |
48724 KB |
Output is correct |
39 |
Correct |
361 ms |
54500 KB |
Output is correct |
40 |
Correct |
335 ms |
41844 KB |
Output is correct |
41 |
Correct |
362 ms |
52848 KB |
Output is correct |
42 |
Correct |
199 ms |
27192 KB |
Output is correct |
43 |
Correct |
200 ms |
27256 KB |
Output is correct |
44 |
Correct |
277 ms |
35716 KB |
Output is correct |
45 |
Correct |
283 ms |
35836 KB |
Output is correct |
46 |
Correct |
297 ms |
35956 KB |
Output is correct |
47 |
Correct |
205 ms |
27256 KB |
Output is correct |
48 |
Correct |
206 ms |
27000 KB |
Output is correct |
49 |
Correct |
278 ms |
35704 KB |
Output is correct |
50 |
Correct |
279 ms |
35704 KB |
Output is correct |
51 |
Correct |
317 ms |
36176 KB |
Output is correct |
52 |
Correct |
250 ms |
34552 KB |
Output is correct |
53 |
Correct |
311 ms |
42136 KB |
Output is correct |
54 |
Correct |
375 ms |
49724 KB |
Output is correct |
55 |
Correct |
305 ms |
42360 KB |
Output is correct |