int lst = -1;
unsigned lstx;
int binary_search(const unsigned *a, int n, unsigned x)
{
int l, r;
l = 0;r = n - 1;
if (lst > 0)
if (x > lstx) l = lst + 1;
else r = lst - 1;
lstx = x;
while (l <= r)
{
int mid = l + r >> 1;
if (a[mid] == x) return mid;
else if (a[mid] < x) l = mid + 1;
else r = mid - 1;
}
}