#include<bits/stdc++.h>
using namespace std;
int bit[200010],n,qu;
void mo(int pos,int x){
while(pos<=n){
bit[pos]=max(bit[pos],x);
pos+=pos&(-pos);
}
return;
}
int q(int pos){
int ans=0;
while(pos){
ans=max(ans,bit[pos]);
pos-=pos&(-pos);
}
return ans;
}
int main(){
//ios::sync_with_stdio(0);
//cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
int a,b;
cin>>a>>b;
mo(i,b);
}
cin>>qu;
int x;
cin>>x;
int ans=0,now=1;
while(now!=n){
ans++;
int x=q(now);
if(x==now){
cout<<"-1\n";
return 0;
}
now=q(now);
}
cout<<ans<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
81 ms |
3480 KB |
Output is correct |
5 |
Correct |
83 ms |
3480 KB |
Output is correct |
6 |
Correct |
90 ms |
3600 KB |
Output is correct |
7 |
Correct |
81 ms |
2900 KB |
Output is correct |
8 |
Correct |
58 ms |
2404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
81 ms |
3480 KB |
Output is correct |
5 |
Correct |
83 ms |
3480 KB |
Output is correct |
6 |
Correct |
90 ms |
3600 KB |
Output is correct |
7 |
Correct |
81 ms |
2900 KB |
Output is correct |
8 |
Correct |
58 ms |
2404 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |