#include <bits/stdc++.h>
#define int long long
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
using namespace std;
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);
int n,k,q;
cin>>n>>k>>q;
vector <int> l(n);
for(int i=0;i<n;i++)cin>>l[i];
vector <int> g[n];
for(int i=0;i<n;i++){
int mx=0;
for(int j=i+1;j<n;j++){
if(l[j]>mx){
mx=l[j];
g[i].pb(j);
g[j].pb(i);
}
if(mx>=l[i])break;
}
}
while(q--){
int a,b;
cin>>a>>b;
a--;
b--;
set <pair <int,int> > st;
vector <int> d(n,1e18);
st.insert({0,a});
d[a]=0;
while(!st.empty()){
int v=st.begin()->second;
st.erase(st.begin());
for(auto to : g[v]){
if(d[to]>d[v]+1){
st.erase({d[to],to});
d[to]=d[v]+1;
st.insert({d[to],to});
}
}
}
int x=d[b]-1;
cout<<x<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
432 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
348 KB |
Output is correct |
2 |
Correct |
554 ms |
9832 KB |
Output is correct |
3 |
Correct |
591 ms |
9552 KB |
Output is correct |
4 |
Correct |
629 ms |
9808 KB |
Output is correct |
5 |
Correct |
640 ms |
9808 KB |
Output is correct |
6 |
Correct |
704 ms |
10312 KB |
Output is correct |
7 |
Correct |
831 ms |
11680 KB |
Output is correct |
8 |
Correct |
238 ms |
7684 KB |
Output is correct |
9 |
Execution timed out |
2066 ms |
8648 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2005 ms |
9664 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2049 ms |
12156 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |