Skip to content

Commit e5d7ec1

Browse files
authored
feat: tree order statistics was updated
1 parent b4986db commit e5d7ec1

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

data_structure/data_structure_tree_order_statistic.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,35 @@ using __gnu_pbds::rb_tree_tag;
99
using __gnu_pbds::tree_order_statistics_node_update;
1010
using __gnu_pbds::null_type;
1111

12+
// _GLIBCXX_DEBUG must not be defined otherwise some internal check will fail
13+
#undef _GLIBCXX_DEBUG
14+
1215
template <typename K, typename V, typename Comp = less<K>>
1316
using indexed_map = tree<K, V, Comp, rb_tree_tag, tree_order_statistics_node_update>;
1417

1518
template <typename K, typename Comp = less<K>>
1619
using indexed_set = indexed_map<K, null_type, Comp>;
1720

21+
// ¡¡IMPORTANT!! (for using less_equals<K>)
1822
// using less_equals<K> makes lower_bound works as upper_bound and vice-versa
23+
// for erase use: any.erase(any.find_by_order(any.order_of_key(val)));
24+
// don't use .find() because it will always return .end()
1925
template <typename K, typename V, typename Comp = less_equal<K>>
2026
using indexed_multimap = indexed_map<K, V, Comp>;
2127

2228
template <typename K, typename Comp = less_equal<K>>
2329
using indexed_multiset = indexed_map<K, null_type, Comp>;
2430

31+
// Reference: https://codeforces.com/blog/entry/11080
32+
2533
// Usage
34+
// 1) Return the value of the idx index
2635
// auto it = any.find_by_order(idx); (0-indexed)
2736
// (*it).first, (*it).second
37+
// 2) Get the index of the key value
2838
// int index = any.order_of_key(key);
29-
// {1: 10, 2 :20, 5: 50}, order_of_key(3) -> return index 2
39+
// {1: 10, 2 :20, 5: 50}
40+
// any.order_of_key(2) -> return index 1
41+
// any.order_of_key(3) -> return index 2
42+
// 3) Correct way to use erase:
43+
// any.erase(any.find_by_order(any.order_of_key(val)));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy