//1L1YA
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3,unrool-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
#define Pb push_back
#define F first
#define S second
#define endl '\n'
#define sep ' '
#define all(x) x.begin(),x.end()
#define al(x,n) x+1,x+n+1
#define SZ(x) ((int)x.size())
#define lc (id<<1)
#define rc (lc|1)
#define mid (l+r>>1)
#define dokme(x) cout << x << endl, exit(0)
#define sik(x) cout << x << endl;continue;
#define FastIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FileIO freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll oo=1e18;
const int mod=1e9+7;
const int inf=1e9+111;
const int N=5e5+11;
const int lg=23;
int n,m,q,a[N],l[N],r[N],lst[N];
vector<int> vc[N],vec[N];
pii val[N],seg[N<<2];
void build(int id=1,int l=1,int r=n+1){
seg[id]={1,n};
if(r-l==1) return;
build(lc,l,mid);
build(rc,mid,r);
}
void update(int ql,int qr,pii val,int id=1,int l=1,int r=n+1){
if(qr<=l || ql>=r) return;
if(ql<=l && r<=qr){
seg[id].F=max(seg[id].F,val.F);
seg[id].S=min(seg[id].S,val.S);
return;
}
update(ql,qr,val,lc,l,mid);
update(ql,qr,val,rc,mid,r);
}
pii get(int pos,int id=1,int l=1,int r=n+1){
if(r-l==1) return seg[id];
pii p;
if(pos<mid) p=get(pos,lc,l,mid);
else p=get(pos,rc,mid,r);
return {max(p.F,seg[id].F),min(p.S,seg[id].S)};
}
int main(){
FastIO
cin >> n;
for(int i=1;i<n;i++) cin >> a[i];
for(int i=1;i<=n;i++){
cin >> m;
for(int j=1;j<=m;j++){
int x;cin >> x;
vc[i].Pb(x);
}
}
for(int i=1;i<n;i++){
for(int j: vc[i]) lst[j]=i;
l[i]=lst[a[i]];
}
fill(lst,lst+n+1,n+1);
for(int i=n;i>1;i--){
for(int j: vc[i]) lst[j]=i;
r[i-1]=lst[a[i-1]];
vec[r[i-1]].Pb(i);
}
build();
set<int> st;
for(int i=0;i<=n;i++){
for(int j: vec[i]) st.erase(j);
if(SZ(st)){
auto it=st.upper_bound(l[i]);
if(it!=st.end()) update(*it,i+1,{1,i});
}
st.insert(i+1);
}
st.clear();
for(int i=0;i<=n+1;i++) vec[i].clear();
for(int i=1;i<n;i++) vec[l[i]].Pb(i);
r[0]=n+1;
for(int i=n+1;i;i--){
for(int j: vec[i]) st.erase(j);
if(SZ(st)){
auto it=st.lower_bound(r[i-1]);
if(it--!=st.begin()) update(i,(*it)+1,{i,n});
}
st.insert(i-1);
}
for(int i=1;i<=n;i++) val[i]=get(i);
cin >> q;
while(q--){
int x,y;
cin >> x >> y;
if(y>=val[x].F && y<=val[x].S) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
Compilation message
long_mansion.cpp: In function 'void build(int, int, int)':
long_mansion.cpp:23:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
23 | #define mid (l+r>>1)
| ~^~
long_mansion.cpp:44:16: note: in expansion of macro 'mid'
44 | build(lc,l,mid);
| ^~~
long_mansion.cpp:23:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
23 | #define mid (l+r>>1)
| ~^~
long_mansion.cpp:45:14: note: in expansion of macro 'mid'
45 | build(rc,mid,r);
| ^~~
long_mansion.cpp: In function 'void update(int, int, pii, int, int, int)':
long_mansion.cpp:23:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
23 | #define mid (l+r>>1)
| ~^~
long_mansion.cpp:55:27: note: in expansion of macro 'mid'
55 | update(ql,qr,val,lc,l,mid);
| ^~~
long_mansion.cpp:23:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
23 | #define mid (l+r>>1)
| ~^~
long_mansion.cpp:56:25: note: in expansion of macro 'mid'
56 | update(ql,qr,val,rc,mid,r);
| ^~~
long_mansion.cpp: In function 'pii get(int, int, int, int)':
long_mansion.cpp:23:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
23 | #define mid (l+r>>1)
| ~^~
long_mansion.cpp:62:12: note: in expansion of macro 'mid'
62 | if(pos<mid) p=get(pos,lc,l,mid);
| ^~~
long_mansion.cpp:23:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
23 | #define mid (l+r>>1)
| ~^~
long_mansion.cpp:62:32: note: in expansion of macro 'mid'
62 | if(pos<mid) p=get(pos,lc,l,mid);
| ^~~
long_mansion.cpp:23:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
23 | #define mid (l+r>>1)
| ~^~
long_mansion.cpp:63:23: note: in expansion of macro 'mid'
63 | else p=get(pos,rc,mid,r);
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
33368 KB |
Output is correct |
2 |
Correct |
7 ms |
33368 KB |
Output is correct |
3 |
Correct |
8 ms |
33628 KB |
Output is correct |
4 |
Correct |
6 ms |
33372 KB |
Output is correct |
5 |
Correct |
6 ms |
33372 KB |
Output is correct |
6 |
Correct |
6 ms |
33372 KB |
Output is correct |
7 |
Correct |
7 ms |
33372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
33368 KB |
Output is correct |
2 |
Correct |
7 ms |
33368 KB |
Output is correct |
3 |
Correct |
8 ms |
33628 KB |
Output is correct |
4 |
Correct |
6 ms |
33372 KB |
Output is correct |
5 |
Correct |
6 ms |
33372 KB |
Output is correct |
6 |
Correct |
6 ms |
33372 KB |
Output is correct |
7 |
Correct |
7 ms |
33372 KB |
Output is correct |
8 |
Correct |
75 ms |
39312 KB |
Output is correct |
9 |
Correct |
68 ms |
39252 KB |
Output is correct |
10 |
Correct |
77 ms |
39532 KB |
Output is correct |
11 |
Correct |
71 ms |
40016 KB |
Output is correct |
12 |
Correct |
67 ms |
38736 KB |
Output is correct |
13 |
Correct |
65 ms |
39628 KB |
Output is correct |
14 |
Correct |
64 ms |
39504 KB |
Output is correct |
15 |
Correct |
64 ms |
39388 KB |
Output is correct |
16 |
Correct |
61 ms |
39256 KB |
Output is correct |
17 |
Correct |
66 ms |
39508 KB |
Output is correct |
18 |
Correct |
66 ms |
39508 KB |
Output is correct |
19 |
Correct |
64 ms |
39508 KB |
Output is correct |
20 |
Correct |
69 ms |
39436 KB |
Output is correct |
21 |
Correct |
62 ms |
39252 KB |
Output is correct |
22 |
Correct |
63 ms |
39272 KB |
Output is correct |
23 |
Correct |
68 ms |
39248 KB |
Output is correct |
24 |
Correct |
67 ms |
39248 KB |
Output is correct |
25 |
Correct |
67 ms |
39340 KB |
Output is correct |
26 |
Correct |
72 ms |
39248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
172 ms |
43344 KB |
Output is correct |
2 |
Correct |
139 ms |
43292 KB |
Output is correct |
3 |
Correct |
129 ms |
43376 KB |
Output is correct |
4 |
Correct |
147 ms |
43344 KB |
Output is correct |
5 |
Correct |
142 ms |
43524 KB |
Output is correct |
6 |
Correct |
104 ms |
43348 KB |
Output is correct |
7 |
Correct |
109 ms |
43600 KB |
Output is correct |
8 |
Correct |
98 ms |
43604 KB |
Output is correct |
9 |
Correct |
100 ms |
43720 KB |
Output is correct |
10 |
Correct |
95 ms |
43564 KB |
Output is correct |
11 |
Correct |
102 ms |
43600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
33368 KB |
Output is correct |
2 |
Correct |
7 ms |
33368 KB |
Output is correct |
3 |
Correct |
8 ms |
33628 KB |
Output is correct |
4 |
Correct |
6 ms |
33372 KB |
Output is correct |
5 |
Correct |
6 ms |
33372 KB |
Output is correct |
6 |
Correct |
6 ms |
33372 KB |
Output is correct |
7 |
Correct |
7 ms |
33372 KB |
Output is correct |
8 |
Correct |
75 ms |
39312 KB |
Output is correct |
9 |
Correct |
68 ms |
39252 KB |
Output is correct |
10 |
Correct |
77 ms |
39532 KB |
Output is correct |
11 |
Correct |
71 ms |
40016 KB |
Output is correct |
12 |
Correct |
67 ms |
38736 KB |
Output is correct |
13 |
Correct |
65 ms |
39628 KB |
Output is correct |
14 |
Correct |
64 ms |
39504 KB |
Output is correct |
15 |
Correct |
64 ms |
39388 KB |
Output is correct |
16 |
Correct |
61 ms |
39256 KB |
Output is correct |
17 |
Correct |
66 ms |
39508 KB |
Output is correct |
18 |
Correct |
66 ms |
39508 KB |
Output is correct |
19 |
Correct |
64 ms |
39508 KB |
Output is correct |
20 |
Correct |
69 ms |
39436 KB |
Output is correct |
21 |
Correct |
62 ms |
39252 KB |
Output is correct |
22 |
Correct |
63 ms |
39272 KB |
Output is correct |
23 |
Correct |
68 ms |
39248 KB |
Output is correct |
24 |
Correct |
67 ms |
39248 KB |
Output is correct |
25 |
Correct |
67 ms |
39340 KB |
Output is correct |
26 |
Correct |
72 ms |
39248 KB |
Output is correct |
27 |
Correct |
172 ms |
43344 KB |
Output is correct |
28 |
Correct |
139 ms |
43292 KB |
Output is correct |
29 |
Correct |
129 ms |
43376 KB |
Output is correct |
30 |
Correct |
147 ms |
43344 KB |
Output is correct |
31 |
Correct |
142 ms |
43524 KB |
Output is correct |
32 |
Correct |
104 ms |
43348 KB |
Output is correct |
33 |
Correct |
109 ms |
43600 KB |
Output is correct |
34 |
Correct |
98 ms |
43604 KB |
Output is correct |
35 |
Correct |
100 ms |
43720 KB |
Output is correct |
36 |
Correct |
95 ms |
43564 KB |
Output is correct |
37 |
Correct |
102 ms |
43600 KB |
Output is correct |
38 |
Correct |
645 ms |
80468 KB |
Output is correct |
39 |
Correct |
574 ms |
85860 KB |
Output is correct |
40 |
Correct |
396 ms |
73040 KB |
Output is correct |
41 |
Correct |
286 ms |
86096 KB |
Output is correct |
42 |
Correct |
132 ms |
51332 KB |
Output is correct |
43 |
Correct |
123 ms |
51028 KB |
Output is correct |
44 |
Correct |
185 ms |
64336 KB |
Output is correct |
45 |
Correct |
175 ms |
64376 KB |
Output is correct |
46 |
Correct |
170 ms |
64596 KB |
Output is correct |
47 |
Correct |
112 ms |
50768 KB |
Output is correct |
48 |
Correct |
145 ms |
50768 KB |
Output is correct |
49 |
Correct |
160 ms |
64244 KB |
Output is correct |
50 |
Correct |
156 ms |
64084 KB |
Output is correct |
51 |
Correct |
157 ms |
64540 KB |
Output is correct |
52 |
Correct |
265 ms |
68152 KB |
Output is correct |
53 |
Correct |
371 ms |
82652 KB |
Output is correct |
54 |
Correct |
468 ms |
94408 KB |
Output is correct |
55 |
Correct |
342 ms |
83344 KB |
Output is correct |