跳到正文

个人记录

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

jijidawang约 2 分钟
原文
文章信息与版本

文章信息

发布
2022年4月2日
收录
2025年12月12日
更新
2026年11月11日
篇幅
约 2 分钟

版本

  1. v1当前

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

好恶毒啊!!

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

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

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

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

For example.

C++
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_mapgp_hash_tablecc_hash_table
simpleTLETLE(90pts)TLE
use Int_HasherACTLE(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

原文