Skip to content

Commit

Permalink
Update OrderStatisticTree.h
Browse files Browse the repository at this point in the history
  • Loading branch information
dothething1DA authored Sep 16, 2024
1 parent e0979db commit 2c8b1b4
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions content/data-structures/OrderStatisticTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,16 @@
* To get a map, change \texttt{null\_type}.
* Time: O(\log N)
*/
#pragma once

#include <bits/extc++.h> /** keep-include */
#include <bits/extc++.h>
using namespace __gnu_pbds;

template<class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag,
tree_order_statistics_node_update>;
// find_by_order(x): return iterator to k-th largest element(count from 0)
// order_of_key(x): number of element strictly less than x

void example() {
Tree<int> t, t2; t.insert(8);
auto it = t.insert(10).first;
assert(it == t.lower_bound(9));
assert(t.order_of_key(10) == 1);
assert(t.order_of_key(11) == 2);
assert(*t.find_by_order(0) == 8);
t.join(t2); // assuming T < T2 or T > T2, merge t2 into t
}
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update
> ost;

0 comments on commit 2c8b1b4

Please sign in to comment.