我正在尝试使用__gnu__pbds实现订单统计树。我遵循了这段代码TREE_ORDER_STATISTICS
但是,我需要在multiset上使用它。我被建议使用一对来实现此功能CODEFORCES COMMENT
//Main idea is to keep pairs like {elem, id}.
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
int t = 0;
ordered_set me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";
但是,我如何在这种情况下使用find_by_order(k)
?
答案 0 :(得分:3)
使用less_equal而不是更少的缺点是,lower_bound用作upper_bound
一种方法是存储货币对
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
int t = 0;
ordered_set me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";
答案 1 :(得分:1)
您需要在以下方式将比较功能从less
更改为less_equal
asn:
typedef tree<
int,
null_type,
less_equal<int>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;