From 2c8b1b43dbf17d0d45f8bf3f3f05ed466a1fd5bc Mon Sep 17 00:00:00 2001 From: dothething <165024975+dothething1DA@users.noreply.github.com> Date: Mon, 16 Sep 2024 16:37:24 +1000 Subject: [PATCH] Update OrderStatisticTree.h --- content/data-structures/OrderStatisticTree.h | 25 ++++++++------------ 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/content/data-structures/OrderStatisticTree.h b/content/data-structures/OrderStatisticTree.h index 8928bc9..b5fe5c7 100644 --- a/content/data-structures/OrderStatisticTree.h +++ b/content/data-structures/OrderStatisticTree.h @@ -8,21 +8,16 @@ * To get a map, change \texttt{null\_type}. * Time: O(\log N) */ -#pragma once - -#include /** keep-include */ +#include using namespace __gnu_pbds; -template -using Tree = tree, 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 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, + rb_tree_tag, + tree_order_statistics_node_update +> ost;