umap 如何防止被卡(详细解密)

· · 个人记录

我们做题的时候总有一些邪恶人员想卡 unordered_map .

好恶毒啊!!

就算用 gp_hash_table,cc_hash_table 此类也会被卡!

怎么防止被卡,其实非常非常的简单 .

既然库里的东西会被卡,那么我们就手写一个呗 .

用法直接在 template 后面缀即可 .

For example.

const int magic1 = 114514, magic2 = 1e9+9;
struct Int_Hasher{std::size_t operator()(const int& rhs)const{return rhs ^ magic1 % magic2;}};

unordered_map<int, int, Int_Hasher>      Test1;
tr1::unordered_map<int, int, Int_Hasher> Test2;
gp_hash_table<int, int, Int_Hasher>      Test3;
cc_hash_table<int, int, Int_Hasher>      Test4;
// 均能通过编译

测试(UOJ127 程序自动分析):

/ unordered_map gp_hash_table cc_hash_table
simple TLE TLE(90pts) TLE
use Int_Hasher AC TLE(90pts) TLE

TLE 未加说明均为 97pts .

P.S. <unodered_map> 和 <tr1/unordered_map> 里面的东西基本是相同的,不用管 .

Bonus: 这种技法可以使你把自己定义的类型 / umap 原生不支持的东西丢到 unordered_map 里 .

e.g. https://www.cnblogs.com/CDOI-24374/p/16063533.html