| Run ID | Author | Problem | Lang | Verdict | Score | Time | Memory | Code Length | Submit Time |
|---|---|---|---|---|---|---|---|---|---|
| 74143 | 桑迪 | 二分查找 | C++ | Accepted | 100 | 19 MS | 644 KB | 349 | 2023-05-20 17:17:23 |
#include<bits/stdc++.h> using namespace std; int n,a[114514],x,ans=-1; void bs(int l,int r){ if(l>=r){ if(a[l]==x)ans=l; return; } int md=(l+r)>>1; if(a[md]>x)bs(l,md-1); else if(a[md]<x)bs(md+1,r); else{ans=md;return;} } int main(){ cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; cin>>x; bs(1,n); cout<<ans; return 0; }