#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define ll long long
#define y1 YONE
typedef unsigned long long ull;
using namespace std;
const int N=2e5+5;
int dis[N],L[N],R[N],n,q;
set<int> s;
void bfs(){
for (int i=2;i<=n;i++) dis[i]=INT_MAX;
queue<int> q;q.push(1);s.erase(1);
while (!q.empty()){
int x=q.front();q.pop();
while (true){
auto it=s.lower_bound(L[x]);
if (it==s.end()) break;
if (*it>R[x]) break;
int y=*it;
s.erase(it);
dis[y]=dis[x]+1;
q.push(y);
}
}return;
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n;
for (int i=1;i<=n;i++) cin>>L[i]>>R[i],s.ep(i);
cin>>q;
while (q--){
int x;cin>>x;
bfs();
int mx=0;
for (int i=1;i<=n;i++) mx=max(mx,dis[i]);
if (mx>=INT_MAX) cout<<-1<<endl;
else cout<<mx<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
61 ms |
14244 KB |
Output is correct |
5 |
Correct |
70 ms |
16724 KB |
Output is correct |
6 |
Correct |
64 ms |
16976 KB |
Output is correct |
7 |
Correct |
63 ms |
15956 KB |
Output is correct |
8 |
Correct |
47 ms |
13652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
61 ms |
14244 KB |
Output is correct |
5 |
Correct |
70 ms |
16724 KB |
Output is correct |
6 |
Correct |
64 ms |
16976 KB |
Output is correct |
7 |
Correct |
63 ms |
15956 KB |
Output is correct |
8 |
Correct |
47 ms |
13652 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |