diff options
| author | Gloria Mundi <gloria@gloria-mundi.eu> | 2024-04-01 19:59:01 +0200 |
|---|---|---|
| committer | Gloria Mundi <gloria@gloria-mundi.eu> | 2024-04-01 19:59:01 +0200 |
| commit | 33343f96d94f2d7f12567b1c227e4e2399c8bd1b (patch) | |
| tree | 16b5ef80ee4605ce88410911fbb6beb6dfc1d7b2 /datastructures/pbds.cpp | |
| parent | 4fc39dcd54243609febc1ce4c8a1470b3d31fd47 (diff) | |
| parent | 98aa28427350e72cb9abe4071c0c6b6870b7e6cc (diff) | |
merge mzuenni changes
Diffstat (limited to 'datastructures/pbds.cpp')
| -rw-r--r-- | datastructures/pbds.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/datastructures/pbds.cpp b/datastructures/pbds.cpp new file mode 100644 index 0000000..a0e5383 --- /dev/null +++ b/datastructures/pbds.cpp @@ -0,0 +1,27 @@ +#include <ext/pb_ds/priority_queue.hpp> +template<typename T> +using pQueue = __gnu_pbds::priority_queue<T>; //<T, greater<T>> +auto it = pq.push(5); // O(1) +pq.modify(it, 6); // O(log n) +pq.erase(it); // O(log n) +pq.join(pq2); // O(1) +pq.swap(pq2); // O(1) + +#include <ext/pb_ds/assoc_container.hpp> +using namespace __gnu_pbds; +template<typename T> +using Tree = tree<T, null_type, less<T>, rb_tree_tag, + tree_order_statistics_node_update>; +T.order_of_key(x); // number of elements strictly less than x +auto it = T.find_by_order(k); // k-th element + +template<typename T> +struct chash { + const uint64_t C = ll(2e18 * acos(-1)) | 199; // random odd + size_t operator()(T o) const { + return __builtin_bswap64(hash<T>()(o) * C); +}}; +template<typename K, typename V> +using hashMap = gp_hash_table<K, V, chash<K>>; +template<typename T> +using hashSet = gp_hash_table<T, null_type, chash<T>>; |
