lowerer_bound&upper_bound

low_bound()

low_bound(beg, end, num, comp)

参数

  1. 数组要low_bound()的起始地址
  2. 数组要low_bound()的截止地址
  3. 要二分查找的那个数
  4. greater<int>()代表降序,less<int>()代表升序,默认是升序,也就是数组元素从小到大排列

返回值
返回第一次出现>=num>=num的数的地址

注意

  1. 返回值是地址,不是查询的数的下标
  2. >=>=

理解
a[5]={1,1,2,3,5}a[5]=\{1, 1, 2, 3, 5\}
low_bound(a,a+5,2)low\_bound(a, a + 5, 2) \to返回第一个>=2>=2的数22

lowerer_bound&upper_bound

upper_bound()

upper_bound函数的用法low_bound函数的用法相似,不过不同的是返回值返回的是一个比要找的树大的地址(>(>無等号))
理解
a[5]={1,1,2,2,4}a[5] = \{1, 1, 2, 2, 4\}
upper_bound(a,a+5,3)upper\_bound(a, a + 5, 3)\to返回第一个>3>3的数44lowerer_bound&upper_bound