二分专题

二分专题

int p=lower_bound(A,A+n,x)-A;          //查询>=x的第一个下标
int p=upper_bound(A,A+n,x)-A;          //查询>x的第一个下标
int p=upper_bound(A,A+n,x)-A-1;         //查询<=x的最后一个下标
int p=lower_bound(A,A+n,x)-A-1;         //查询<x的最后一个下标
int n=upper_bound(A,A+n)-lower_bound(A,A+n);  //查询等于x的数量

  

编译人生,运行世界!
原文地址:https://www.cnblogs.com/Running-Time/p/4658522.html