相关疑难解决方法(0)

C++ set:计算小于值的元素

假设我有一个STL set <int> s和一个int x,我怎么能计算出s少于的元素数x

我正在寻找一个O(log n)(或类似的;任何比它更合理的O(n))解决方案;

我已经知道了std::distance(s.begin(), s.lower_bound(x)),但O(n)我相信,因为sets不是随机访问.

c++ algorithm performance complexity-theory stl

25
推荐指数
3
解决办法
5995
查看次数

标签 统计

algorithm ×1

c++ ×1

complexity-theory ×1

performance ×1

stl ×1