【学习笔记】pb_ds

__gnu_pbds::priority_queue

#include <ext/pb_ds/priority_queue.hpp>
//using namespace __gnu_pbds;

//__gnu_pbds::priority_queue<T,Cmp,Tag,Allocator>

// __gnu_pbds::priority_queue<T>;
// __gnu_pbds::priority_queue<T,greater<T>>;
__gnu_pbds::priority_queue<T,greater<T>,pairing_heap_tag> q; // default
__gnu_pbds::priority_queue<int>::point_iterator id;  // 点迭代器

//q.
push(x); // return it
pop();
top();
size();
empty();
modify(it,key);
erase(it);
join(anotherpq); // 将 anotherpq 合并到 q 并清空 anotherpq

__gnu_pbds::tree

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

//__gnu_pbds::tree<T,Mapped,Cmp_Fn,Raf,Node_Update,Allocator>

__gnu_pbds::tree<T,__gnu_pbds::null_type,
		std::less<T>,__gnu_pbds::rb_tree_tag,
		__gnu_pbds::tree_order_statistics_node_update>
		trr;
// 定义 T 类型的红黑树。

//trr.
insert(x); // return std::pair<point_iterator,bool> 插入位置的迭代器, 是否插入成功
erase(x); // return bool 是否删除成功
erase(it); // return it==end()?end():next_it
// 以下函数以 Cmp_Fn 作为比较逻辑,排名从 0 开始
order_of_key(x); // 返回严格小于 x 的元素个数
find_by_order(x); // 返回排名为 x 的元素的迭代器
lower_bound(x); // 返回第一个大于等于 x 的元素所对应的迭代器
upper_bound(x): // 返回第一个严格大于 x 的元素所对应的迭代器
//
join(anothertrr); // 将 anothertrr 并入 trr, 并清空 anothertrr。注意:两树值域不能相交,即并入属内所有值必须全部大于/小于当前树内所有值。
split(x,anothertrr); // 将 trr 中小于等于 x 的元素分裂到 trr,其余分裂到 anothertrr
empty();
size();

__gnu_pb_ds::gp_hash_table & __gnu_pb_ds::cc_hash_table

#include <ext/pb_ds/hash_policy.hpp>
#inlcude <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

__gnu_pbds::gp_hash_table<T1,T2> mp1;
__gnu_pbds::cc_hash_table<T1,T2> mp2;

note:
std::map mp.count(x)!=0
__gnu_pbds::gp_hash_table mp.find(x)!=end


// template from magic_team

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
using u64=unsigned long long;

mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
struct Hash
{
	u64 operator ()(u64 x) const 
	{
		static const u64 s1=rnd(),s2=rnd(),s3=rnd();
		x+=s1;
		x=(x^(x>>33))*s2;
		x=(x^(x>>30))*s3;
		return x;
	}
};

__gnu_pbds::gp_hash_table<u64,u64,Hash> mp;
posted @ 2025-08-22 15:05  Akuto_urusu  阅读(11)  评论(0)    收藏  举报