#include <stdio.h>
#include <stdlib.h>
int binary_search(int a[],int n,int x){
int ret=-1;
int lef,mid,rig;
lef=0;
rig=n-1;
while(lef<=rig){
mid=(lef+rig)/2;
if(a[mid]==x){
ret=mid;
break;
}
if(x<a[mid]) rig=mid-1;
else lef=mid+1;
}
return ret;
}
int main(void) {
int n,x,i;
int *a;
int ans = -1;
a
= (int*)malloc(sizeof(int)*n
); if(a==NULL){
return -1;
}
for(i=0;i<n;i++){
}
ans = binary_search(a,n,x);
if(ans
!= -1) printf("a[%d] = %d\n",ans
,a
[ans
]); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KIAppbnQgYmluYXJ5X3NlYXJjaChpbnQgYVtdLGludCBuLGludCB4KXsKCWludCByZXQ9LTE7CglpbnQgbGVmLG1pZCxyaWc7CglsZWY9MDsKCXJpZz1uLTE7Cgl3aGlsZShsZWY8PXJpZyl7CgkJbWlkPShsZWYrcmlnKS8yOwoJCWlmKGFbbWlkXT09eCl7CgkJCXJldD1taWQ7CgkJCWJyZWFrOwoJCX0KCQlpZih4PGFbbWlkXSkgcmlnPW1pZC0xOwoJCWVsc2UgbGVmPW1pZCsxOwoJfQoJcmV0dXJuIHJldDsKfQogCmludCBtYWluKHZvaWQpIHsKCWludCBuLHgsaTsKCWludCAqYTsKCWludCBhbnMgPSAtMTsKCXNjYW5mKCIlZCAlZCIsJm4sJngpOwoJYSA9IChpbnQqKW1hbGxvYyhzaXplb2YoaW50KSpuKTsKCWlmKGE9PU5VTEwpewoJCXByaW50ZigiRVJST1JcbiIpOwoJCXJldHVybiAtMTsKCX0KCWZvcihpPTA7aTxuO2krKyl7CgkJc2NhbmYoIiVkIiwmYVtpXSk7Cgl9CglhbnMgPSBiaW5hcnlfc2VhcmNoKGEsbix4KTsKCWlmKGFucyAhPSAtMSkgcHJpbnRmKCJhWyVkXSA9ICVkXG4iLGFucyxhW2Fuc10pOwoJZWxzZSBwcmludGYoIm5vdCBmb3VuZFxuIik7CglmcmVlKGEpOwoJcmV0dXJuIDA7Cn0=