Generate ready-to-paste C++ Order Statistics Tree code. Configure key type, comparator, and duplicate support. One-click copy.
Yes, completely free. No sign-up, no credit card, no usage limits.
Never. Everything runs 100% in your browser. Nothing is uploaded to any server.
Yes. All tools are fully responsive and work on phones, tablets, and desktops.
Configure Your PBDS Tree
Generated C++ Code
// PBDS Order Statistics Tree — generated by UtilityToolsLab
// Requires: GCC with policy-based headers
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
// Tree type alias
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update
> ordered_set;
// Wrapper with helper methods
struct OST {
ordered_set tree;
void insert(int val) { tree.insert(val); }
// find_by_order: k-th element (0-indexed)
int find_by_order(int k) {
return *tree.find_by_order(k);
}
// order_of_key: number of elements strictly less than val
int order_of_key(int val) { return tree.order_of_key(val); }
void erase(int val) { tree.erase(val); }
int size() { return tree.size(); }
bool empty() { return tree.empty(); }
};
// Usage example:
// OST ost;
// ost.insert(5); ost.insert(3); ost.insert(7);
// cout << ost.order_of_key(5) << endl; // 1 (one element < 5)
// cout << ost.find_by_order(0) << endl; // 3 (smallest)
Key Operations Reference
ost.insert(x)Insert element xost.order_of_key(x)# elements strictly < xost.find_by_order(k)k-th element (0-indexed)ost.erase(x)Remove one occurrence of x