@aimat 说是不是你干的
就是说 umap / uset 理论时间复杂度是 O(1) 的但是实际上因为底层是变长哈希表实现,但是变化的长度在给定的编译器版本内是固定的,所以说可以被卡到 O(n),具体见 https://codeforces.com/blog/entry/62393, https://codeforces.com/blog/entry/141849
几个解决方案是:
- 用 C++14(GCC9) 交(因为懒惰的hack人只卡了GCC11忘记卡GCC9的umap了)
- 换成
map/set
- 自定义umap/uset的哈希函数:
struct myhash
{
static uint64_t rand(uint64_t x)
{
x ^= x << 13;
x ^= x >> 7;
return x ^= x << 17;
}
size_t operator()(size_t x) const
{
static const uint64_t f_rand = chrono::steady_clock::now().time_since_epoch().count();
return rand(x + f_rand);
}
};
然后用 umap/uset 可以这样:
std::unordered_map<_Type1, _Type2, myhash> name
std::unordered_set<_Type1, myhash> name
这个东西也兼容 __gnu_pbds::gp_hash_table / __gnu_pbds::cc_hash_table
用法和上面的类似
据说这样不论怎么构造数据都不会被卡掉