C++ set: counting elements less than a value

后端 未结 3 1140
臣服心动
臣服心动 2020-12-24 12:26

Assuming a I have an STL set s and an int x, how can I count the number of elements in s that are less than x

3条回答
  •  情深已故
    2020-12-24 12:55

    As a follow up to my comment: using red-black binary search trees (instead of sets), if each node stores the number of nodes rooted in that node (updated every time you insert/delete a node) then you can get at "number of nodes more than/less than X" statistics quite fast.

提交回复
热议问题