4 solutions
-
0
#include <stdio.h> void find(int x,int n,int a[]) { int l=-1; int r=n; while(l+1<r){ int mid=(l+r)/2; if(a[mid]>x){ r=mid; }else{ l=mid; } } if(a[r-1]==x){ printf("%d ",r); }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
- 1231
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 7
- Tags
- # Submissions
- 342
- Accepted
- 90
- Uploaded By