代码
#include<bits/stdc++.h>
using namespace std;
int a[1100000];
int main()
{
int n,x,l,r,p,mid,i;
cin>>n;
for(i=1;i<=n;i++)
cin>>a[i];
cin>>x;
l=1;
r=n;
p=-1;
while(l<=r)
{
mid=(r+l)/2;
if(a[mid]==x)
{
p=mid;
break;
}
else if(x<a[mid]) r=mid-1;
else if(x>a[mid]) l=mid+1;
}
cout<<(p==-1?-1:p);
return 0;
}