This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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,qu;
cin>>n>>k>>qu;
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(qu--){
int a,b;
cin>>a>>b;
a--;
b--;
queue <int> q;
vector <int> d(n,1e18);
q.push(a);
d[a]=0;
while(!q.empty()){
int v=q.front();
q.pop();
for(auto to : g[v]){
if(d[to]>d[v]+1){
d[to]=d[v]+1;
q.push(to);
}
}
}
int x=d[b]-1;
cout<<x<<"\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |