AOJやりまくってる
指定した配列(sorted)に指定された値が含まれているかどうかを判定するやつ
bool binarysearch(int[] a, int x) { if(a.length==0) return false; if(a[0]==x || a[$-1]==x) return true; uint from = 0; uint to = cast(uint)(a.length-1); while(to-from>1) { uint med = (from+to) >> 1; if(a[med]==x) return true; if(a[med]>x) to = med; else from = med; } return false; }
こんなもんでいいよな…