#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<long long,long long>pii;
typedef pair<int,pii>pi2;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
void solve(){
int n;
cin >> n;
int arr[n+1];
for(int x=1;x<n;x++){
cin >> arr[x];
}
vector<int>storage[n+5];
int temp,temp2;
for(int x=1;x<=n;x++){
cin >> temp;
for(int y=0;y<temp;y++){
cin >> temp2;
storage[x].push_back(temp2);
}
}
pii ans[n+5];
for(int x=1;x<=n;x++){
int l=x;
int r=x;
set<int>se;
for(auto it:storage[x]) se.insert(it);
while(1){
if(l!=1&&se.find(arr[l-1])!=se.end()){
l--;
for(auto it:storage[l]) se.insert(it);
}
else if(r!=n&&se.find(arr[r])!=se.end()){
r++;
for(auto it:storage[r]) se.insert(it);
}
else break;
}
ans[x]={l,r};
}
int q;
cin >> q;
for(int x=0;x<q;x++){
cin >> temp >> temp2;
if(ans[temp].first<=temp2&&ans[temp].second>=temp2){
cout << "YES\n";
}
else cout << "NO\n";
}
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//freopen("in.txt","r",stdin);
//cin >> t;
while(t--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
600 KB |
Output is correct |
2 |
Correct |
106 ms |
604 KB |
Output is correct |
3 |
Correct |
238 ms |
900 KB |
Output is correct |
4 |
Correct |
13 ms |
604 KB |
Output is correct |
5 |
Correct |
303 ms |
652 KB |
Output is correct |
6 |
Correct |
96 ms |
704 KB |
Output is correct |
7 |
Correct |
79 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
600 KB |
Output is correct |
2 |
Correct |
106 ms |
604 KB |
Output is correct |
3 |
Correct |
238 ms |
900 KB |
Output is correct |
4 |
Correct |
13 ms |
604 KB |
Output is correct |
5 |
Correct |
303 ms |
652 KB |
Output is correct |
6 |
Correct |
96 ms |
704 KB |
Output is correct |
7 |
Correct |
79 ms |
600 KB |
Output is correct |
8 |
Correct |
99 ms |
6348 KB |
Output is correct |
9 |
Correct |
78 ms |
6280 KB |
Output is correct |
10 |
Correct |
186 ms |
6680 KB |
Output is correct |
11 |
Correct |
314 ms |
7252 KB |
Output is correct |
12 |
Correct |
116 ms |
5964 KB |
Output is correct |
13 |
Correct |
85 ms |
6684 KB |
Output is correct |
14 |
Correct |
82 ms |
6740 KB |
Output is correct |
15 |
Correct |
222 ms |
6816 KB |
Output is correct |
16 |
Correct |
378 ms |
6484 KB |
Output is correct |
17 |
Correct |
76 ms |
6668 KB |
Output is correct |
18 |
Correct |
89 ms |
6648 KB |
Output is correct |
19 |
Correct |
126 ms |
6608 KB |
Output is correct |
20 |
Correct |
361 ms |
6592 KB |
Output is correct |
21 |
Correct |
373 ms |
6336 KB |
Output is correct |
22 |
Correct |
302 ms |
6484 KB |
Output is correct |
23 |
Correct |
199 ms |
6420 KB |
Output is correct |
24 |
Correct |
177 ms |
6484 KB |
Output is correct |
25 |
Correct |
149 ms |
6480 KB |
Output is correct |
26 |
Correct |
107 ms |
6404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3060 ms |
12860 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
600 KB |
Output is correct |
2 |
Correct |
106 ms |
604 KB |
Output is correct |
3 |
Correct |
238 ms |
900 KB |
Output is correct |
4 |
Correct |
13 ms |
604 KB |
Output is correct |
5 |
Correct |
303 ms |
652 KB |
Output is correct |
6 |
Correct |
96 ms |
704 KB |
Output is correct |
7 |
Correct |
79 ms |
600 KB |
Output is correct |
8 |
Correct |
99 ms |
6348 KB |
Output is correct |
9 |
Correct |
78 ms |
6280 KB |
Output is correct |
10 |
Correct |
186 ms |
6680 KB |
Output is correct |
11 |
Correct |
314 ms |
7252 KB |
Output is correct |
12 |
Correct |
116 ms |
5964 KB |
Output is correct |
13 |
Correct |
85 ms |
6684 KB |
Output is correct |
14 |
Correct |
82 ms |
6740 KB |
Output is correct |
15 |
Correct |
222 ms |
6816 KB |
Output is correct |
16 |
Correct |
378 ms |
6484 KB |
Output is correct |
17 |
Correct |
76 ms |
6668 KB |
Output is correct |
18 |
Correct |
89 ms |
6648 KB |
Output is correct |
19 |
Correct |
126 ms |
6608 KB |
Output is correct |
20 |
Correct |
361 ms |
6592 KB |
Output is correct |
21 |
Correct |
373 ms |
6336 KB |
Output is correct |
22 |
Correct |
302 ms |
6484 KB |
Output is correct |
23 |
Correct |
199 ms |
6420 KB |
Output is correct |
24 |
Correct |
177 ms |
6484 KB |
Output is correct |
25 |
Correct |
149 ms |
6480 KB |
Output is correct |
26 |
Correct |
107 ms |
6404 KB |
Output is correct |
27 |
Execution timed out |
3060 ms |
12860 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |