提交时间:2023-05-20 17:26:13

运行 ID: 74207

#include<bits/stdc++.h> using namespace std; long long n,a[110000]; int main(){ cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; int x; int left=1,right=n,mid; cin>>x; while(left<=right){ mid=(left+right)/2; if(a[mid]<=x) left=mid+1; else right=mid-1; } if(a[right]==x) cout<<right; else cout<<-1; return 0; }