1 solutions
-
0
#include<bits/stdc++.h> using namespace std; #define ll long long const ll N=1e8+5; ll a[N],n,k,l,r; ll find(ll g){ l=1,r=n; while(l<=r){ ll mid=(l+r)/2; if(a[mid]<=g){ l=mid+1; } else{ r=mid-1; } } if(a[l-1]==g){ return l-1; } else{ return -1; } } int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } cin>>k; cout<<find(k); return 0; }
- 1
Information
- ID
- 576
- Time
- 1000ms
- Memory
- 64MiB
- Difficulty
- 6
- Tags
- # Submissions
- 188
- Accepted
- 55
- Uploaded By