How pbds works
  • 板块学术版
  • 楼主henryhu2006
  • 当前回复3
  • 已保存回复3
  • 发布时间2023/8/27 22:26
  • 上次更新2023/11/3 00:48:22
查看原帖
How pbds works
133060
henryhu2006楼主2023/8/27 22:26
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
gp_hash_table<int,int> mp;
int main(){
	for(int i=1;i<=1000;++i){
		mp[2*i+1]=mp[2*i]=i;
		cout<<mp[2*i+1]<<" "<<mp[2*i]<<endl;
	}
	return 0;
}

这个 gp_hash_table 的代码看似没有什么问题,但是输出却是:

1 1
0 2
3 3
0 4
5 5
6 6
7 7
0 8
9 9
10 10
11 11
12 12
13 13
14 14
15 15
0 16
...

在所有二的幂次处都会出现赋值失败的问题,且仅出现在连等的时候。盲猜是因为内存扩容时执行顺序有 bug,求解答。

2023/8/27 22:26
加载中...