#include <stdio.h>
#include <stdlib.h>
//この関数を実装する
int binary_search(int a[],int n,int x){
//この関数の内側だけを書く
int mid,lef,rig;
int ret=-1;
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+CiNpbmNsdWRlIDxzdGRsaWIuaD4KIAovL+OBk+OBrumWouaVsOOCkuWun+ijheOBmeOCiwppbnQgYmluYXJ5X3NlYXJjaChpbnQgYVtdLGludCBuLGludCB4KXsKCS8v44GT44Gu6Zai5pWw44Gu5YaF5YG044Gg44GR44KS5pu444GPCglpbnQgbWlkLGxlZixyaWc7CglpbnQgcmV0PS0xOwoJbGVmPTA7CglyaWc9bi0xOwoJd2hpbGUobGVmPD1yaWcpewoJCW1pZD0obGVmK3JpZykvMjsKCQlpZihhW21pZF09PXgpewoJCQlyZXQ9bWlkOwoJCQlicmVhazsKCQl9CgkJaWYoeDxhW21pZF0pIHJpZz1taWQtMTsKCQllbHNlIGxlZj1taWQrMTsKCX0KCXJldHVybiByZXQ7Cn0KIAppbnQgbWFpbih2b2lkKSB7CglpbnQgbix4LGk7CglpbnQgKmE7CglpbnQgYW5zID0gLTE7CglzY2FuZigiJWQgJWQiLCZuLCZ4KTsKCWEgPSAoaW50KiltYWxsb2Moc2l6ZW9mKGludCkqbik7CglpZihhPT1OVUxMKXsKCQlwcmludGYoIkVSUk9SXG4iKTsKCQlyZXR1cm4gLTE7Cgl9Cglmb3IoaT0wO2k8bjtpKyspewoJCXNjYW5mKCIlZCIsJmFbaV0pOwoJfQoJYW5zID0gYmluYXJ5X3NlYXJjaChhLG4seCk7CglpZihhbnMgIT0gLTEpIHByaW50ZigiYVslZF0gPSAlZFxuIixhbnMsYVthbnNdKTsKCWVsc2UgcHJpbnRmKCJub3QgZm91bmRcbiIpOwoJZnJlZShhKTsKCXJldHVybiAwOwp9