# What's wrong?

#include<bits/stdc++.h>
#define ll int
using namespace std;
void swap(ll *a,ll *b)
{
ll temp=*a;*a=*b;*b=temp;
}
ll binarySearch(ll arr[],ll pos[],ll l,ll r, ll x,ll ps,ll pl)
{
ll cnt=0,c=r;
while (l <= r)
{
//for(int i=1;i<=c;i++)cout<<arr[i]<<" ";
//cout<<endl;
int m = (l +r)/2;
if (arr[m] == x)
return cnt;
else if(arr[m]<x)
{
if(pos[x]<m){
if(x!=arr[pl]){
swap(&arr[m],&arr[pl]);pl=m;cnt++;r=m-1;}
else return -1;
}
else if(pos[x]>m)l=m + 1;
}
else
{
if(pos[x]>m){
if(x!=arr[ps]){
swap(&arr[m],&arr[ps]);ps=m;cnt++;l=m+1;}
else return -1;
}
else if(pos[x]<m)r = m - 1;
}
}
// return -1;
}
int main()
{
int t;cin>>t;
while(tâ€“)
{
ll n,q;cin>>n>>q;
ll ar[n+1];
for(ll i=1;i<=n;i++)cin>>ar[i];
ll ps=1,pl=1;
ll small=ar1;
for(ll i=2;i<=n;i++)if(ar[i]<small){small=ar[i];ps=i;}
ll large=ar1;
for(ll i=2;i<=n;i++)if(ar[i]>large){large=ar[i];pl=i;}

``````        ll poa[1`enter code here`000000005];
for(ll i=1;i<=n;i++)poa[ar[i]]=i;
while(q--)
{
ll x;cin>>x;
ll br[n+1];
for(ll i=1;i<=n;i++)br[i]=ar[i];
cout<<binarySearch(br,poa,1,n,x,ps,pl)<<endl;
}
}
}
``````

Where is mistake for Fake Binary search

Input

1

7 2

7 6 5 4 3 2 1

3

5