二分查找
(0 n-1)
int find(int a[],int left,int right,int m)
{
while(left<=right)
{
int mid=(right+left)/2;
if(a[mid]==m) return mid;
` else if(a[mid]<m)
left=mid+1;
else
right=mid-1;
}
return -1;
}
求出序列中第一个大于x的数
(0, n)
int lower_bound(int a[],int left,int right,int m)
{
while(left<right)
{
int mid=(right+left)/2;
if(a[mid]>m)
right=mid;
else
left=mid+1;
}
return left;
}