简体   繁体   English

元素数量严格小于给定数量

[英]number of elements strictly lesser than a given number

I want a data structure in which I want to insert elements in log(n) time and the elements should be sorted in the ds after every insertion. 我想要一个数据结构,其中我想在log(n)时间插入元素,并且元素应该在每次插入后在ds中排序。 I can use a multiset for this. 我可以使用multiset。

After that I want to find the numbers of elements strictly smaller than a given number again in log(n) time. 之后我想在log(n)时间内再次找到严格小于给定数字的元素数。 And yes duplicates are also present and they need to be considered. 是的重复也存在,他们需要考虑。 For example if the query element is 5 and the ds contains {2, 2, 4, 5, 6, 8, 8} then answer would be 3(2, 2, 4) as these 3 elements are stricly lesser than 5 例如,如果查询元素是5并且ds包含{2,2,4,5,6,8,8},那么答案将是3(2,2,4),因为这3个元素严格小于5

I could have used multiset but even if I use upper_bound I will have to use distance method which runs in linear time. 我可以使用multiset,但即使我使用upper_bound,我也必须使用以线性时间运行的distance方法。 How can I achieve this efficiently with c++ stl. 如何使用c ++ stl有效地实现这一目标。 Also I cannot use 我也不能用

The data structure you need is an order statistic tree: https://en.wikipedia.org/wiki/Order_statistic_tree 您需要的数据结构是订单统计树: https//en.wikipedia.org/wiki/Order_statistic_tree

The STL doesn't have one, and they're not very common so you might have to roll your own. STL没有,它们不是很常见,所以你可能不得不自己动手。 You can find code in Google, but I can't vouch for any specific implementation. 您可以在Google中找到代码,但我无法保证任何具体的实施。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 返回一个数组,其中包含小于或等于给定数组中元素的数组中的元素数 - Return an array which contains number of elements in an array that is lesser or equal to elements in a given array std::set 方法获取低于给定元素的元素数? - std::set method to get number of elements lower than a given element? 在函数调用中,Entry日志的数量比出口处的日志数量少得多。 这是为什么? - In a function call, the number of Entrance logs are much lesser than the number of logs at the exit. Why is that? 获取大于一个数字的元素数量 - Get number of elements greater than a number 给定范围内的子矩阵中唯一元素的数量? - The number of unique elements in a submatrix with elements in a given range? 小于X的元素数 - Number of elements less than X 写一个返回堆栈的函数,该函数包含小于给定数字的所有元素,并且顺序相同? - Write a function that returns a stack, that contains all elements smaller than a given number, and in same order? 无法创建具有给定数量元素的链表 - Unable to create a linked list with given number of elements Cuda 元素数量大于分配的线程 - Cuda number of elements is larger than assigned threads 计算 BST 中小于 X 的元素数 - counting number of elements less than X in a BST
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM