Skip to content
Snippets Groups Projects
Commit 1790f798 authored by bruno.tissei's avatar bruno.tissei
Browse files

Add policy tree

parent 3bdc0611
No related branches found
No related tags found
No related merge requests found
/**
* Policy Tree
*
* Complexity (Time):
* insert -> O(log n)
* erase -> O(log n)
* find_by_order -> O(log n)
* order_of_key -> O(log n)
* Complexity (Space): O(n)
*/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> set_t;
void operations() {
set_t S;
// Insert element in S
S.insert(x);
// Remove element from S
S.erase(x);
// Returns iterator to the k-th largest element (counting from zero)
int pos = *S.find_by_order(k);
// Returns the number of items strictly smaller than x
int ord = S.order_of_key(x)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment