#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include <bits/stdc++.h>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define all(a) a.begin(),a.end()
using namespace std;
#define maxn 200005
ll n,q;
pll a[maxn];
ll mx[maxn];
int main(){
ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
cin >> n;
for(ll i = 1;i<=n;i++) cin >> a[i].fi >> a[i].sc;
for(ll i = 1;i<=n;i++) mx[i] = max(mx[i-1],a[i].sc);
ll ans = 0;
cin >> q;
cin >> q;
ll i = 1;
ll r = a[i].sc;
if(r==1){
cout<<-1<<endl;
return 0;
}
while(i!=n){
i = r;
if(r!=n&&r==mx[r]){
cout<<-1<<endl;
return 0;
}
r = mx[r];
ans++;
}
cout<<ans<<endl;
return 0;
}
/**
4
1 3
2 4
2 3
4 4
1
1
**/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
29 ms |
4812 KB |
Output is correct |
5 |
Correct |
33 ms |
4844 KB |
Output is correct |
6 |
Correct |
34 ms |
5016 KB |
Output is correct |
7 |
Correct |
39 ms |
4860 KB |
Output is correct |
8 |
Correct |
24 ms |
3916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
29 ms |
4812 KB |
Output is correct |
5 |
Correct |
33 ms |
4844 KB |
Output is correct |
6 |
Correct |
34 ms |
5016 KB |
Output is correct |
7 |
Correct |
39 ms |
4860 KB |
Output is correct |
8 |
Correct |
24 ms |
3916 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |