C++中的顺序统计树

Order Statistic Tree in C++

本文关键字:统计 顺序 C++      更新时间:2023-10-16

我需要标准GCC STL映射容器的订单统计树。

我检查了一下,有一种叫做PBDS的东西。基于策略的数据结构。我也不清楚这种用法。

任何人都可以告诉我如何使用 STL 映射容器进行订单统计树?即使它只在 GNU G++ 上就足够了?

以下是作为顺序统计树实现的GNU基于策略的STL MAP的示例(在Linux gcc 4.6.1上测试):

#include <iostream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef
tree<
  int,
  int,
  less<int>,
  rb_tree_tag,
  tree_order_statistics_node_update>
map_t;
int main()
{
  map_t s;
  s.insert(make_pair(12, 1012));
  s.insert(make_pair(505, 1505));
  s.insert(make_pair(30, 1030));
  cout << s.find_by_order(1)->second << 'n';
  return 0;
}

这是GNU基于策略的数据结构概述的链接。这是其他tree_order_statistics示例。我找不到基于策略的数据结构的良好参考,但您可以使用这些链接以及 PBDS 源。