lower_bound( )和upper_bound( )都是利用二分查找的方法在一个排好序的数组中进行查找的
upper_bound()
#include <algorithm>
功能:查找非递减序列[first,last) 内第一个大于某个元素的位置。
返回值:如果找到返回找到元素的地址否则返回last的地址。
用法:int t=upper_bound(a+l,a+r,key)-a;(a是数组)。
lower_bound
查找非递减序列[first,last) 内第一个大于或等于某个元素的位置。//注意这个是大于等于
返回值:如果找到返回找到元素的地址否则返回last的地址。(这样不注意的话会越界,小心)
用法:int t=lower_bound(a+l,a+r,key)-a;(a是数组)。