#include <stdio.h>
#include <stdlib.h>
int binary_search(int a[],int n,int x){
int ret,left,right,middle;
left=0;
right=n-1;
ret=-1;
while(left<=right){
middle=(left+right)/2;
if(a[middle]==x){ ret=middle; break; }
if(x<a[middle]) { right=middle-1; }
else { left=middle+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+CiNpbmNsdWRlIDxzdGRsaWIuaD4KIAogaW50IGJpbmFyeV9zZWFyY2goaW50IGFbXSxpbnQgbixpbnQgeCl7CglpbnQgcmV0LGxlZnQscmlnaHQsbWlkZGxlOwoJbGVmdD0wOwoJcmlnaHQ9bi0xOwoJcmV0PS0xOwoJd2hpbGUobGVmdDw9cmlnaHQpewoJCW1pZGRsZT0obGVmdCtyaWdodCkvMjsKCQlpZihhW21pZGRsZV09PXgpeyByZXQ9bWlkZGxlOyBicmVhazsgfQoJCWlmKHg8YVttaWRkbGVdKSB7IHJpZ2h0PW1pZGRsZS0xOyB9CgkJZWxzZSB7IGxlZnQ9bWlkZGxlKzE7IH0KCX0KCXJldHVybiByZXQ7Cn0KIAppbnQgbWFpbih2b2lkKSB7CglpbnQgbix4LGk7CglpbnQgKmE7CglpbnQgYW5zID0gLTE7CglzY2FuZigiJWQgJWQiLCZuLCZ4KTsKCWEgPSAoaW50KiltYWxsb2Moc2l6ZW9mKGludCkqbik7CglpZihhPT1OVUxMKXsKCQlwcmludGYoIkVSUk9SXG4iKTsKCQlyZXR1cm4gLTE7Cgl9Cglmb3IoaT0wO2k8bjtpKyspewoJCXNjYW5mKCIlZCIsJmFbaV0pOwoJfQoJYW5zID0gYmluYXJ5X3NlYXJjaChhLG4seCk7CglpZihhbnMgIT0gLTEpIHByaW50ZigiYVslZF0gPSAlZFxuIixhbnMsYVthbnNdKTsKCWVsc2UgcHJpbnRmKCJub3QgZm91bmRcbiIpOwoJZnJlZShhKTsKCXJldHVybiAwOwp9Cg==