2 solutions
-
0
#include <stdio.h> void find(int k,int n,int a[]) { int l=-1; int r=n; while(l+1<r){ int mid=(r+l)/2; if(a[mid]>k){ r=mid; } else{ l=mid; } } if(a[l]==k){ while(a[l]==k){ l--; if(a[l]!=k){ l++; printf("%d ",l+1); break; } } } else{ printf("-1 "); } } int main() { int n,m,i; scanf("%d",&n); int a[n]; for(i=0;i<n;i++){ scanf("%d",&a[i]); } scanf("%d",&m); while(m>0){ int q; scanf("%d",&q); find(q,n,a); m--; } return 0; }
Information
- ID
- 1230
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 5
- Tags
- # Submissions
- 241
- Accepted
- 90
- Uploaded By