This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e2+50;
const ll mod=1e9+7;
using namespace std;
int n,qr,k,l[nmax],v[nmax],d[nmax],i,j,x,y,z;
vector<int>g[nmax];
queue<int>q;
int main()
{
//freopen("sol.in","r",stdin);
//freopen("sol.out","w",stdout);
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
cin>>n>>k>>qr;
for(i=1;i<=n;i++)cin>>l[i];
for(i=1;i<=n;i++)
{
for(j=i-1;j>=1;j--)
{
if(l[j]>=l[i])
{
g[i].pb(j);
g[j].pb(i);
break;
}
}
for(j=i+1;j<=n;j++)
{
if(l[j]>=l[i])
{
g[i].pb(j);
g[j].pb(i);
break;
}
}
}
while(qr--)
{
cin>>x>>y;
for(i=1;i<=n;i++)v[i]=d[i]=0;
q.push(x);
v[x]=1;
while(!q.empty())
{
x=q.front();
q.pop();
for(i=0;i<(int)g[x].size();i++)
{
z=g[x][i];
if(v[z])continue;
v[z]=1;
q.push(z);
d[z]=d[x]+1;
}
}
cout<<d[y]-1<<'\n';
}
return 0;
}
# | 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... |