forked from yosupo06/library-checker-problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunordered_map_killer.cpp
More file actions
64 lines (54 loc) · 1.44 KB
/
Copy pathunordered_map_killer.cpp
File metadata and controls
64 lines (54 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <vector>
#include <tuple>
#include "random.h"
#include "../params.h"
using namespace std;
/*
このコードでMAGICが計算可能
参考 https://kmyk.github.io/blog/blog/2017/03/08/unordered-map-hash-collision/
#include <iostream>
#include <unordered_map>
using ll = long long;
using namespace std;
int main() {
int m = 1000000;
unordered_map<int,int> f;
int old = -1;
for (int i = 0; i < m; i++) {
int now = int(f.bucket_count());
if (old != now) {
cout << old << " -> " << now << endl;
old = now;
}
f[i] = i;
}
return 0;
}
*/
int main(int, char* argv[]) {
long long seed = atoll(argv[1]);
auto gen = Random(seed);
// magic for ideone, judge, clang++(OS X)
int MAGIC = vector<int>({256279, 218971, 205759})[seed % 3];
int Q = Q_MAX;
printf("%d\n", Q);
vector<long long> keys;
for (long long i = 0; i <= K_AND_V_MAX; i += MAGIC) {
keys.push_back(i);
if (int(keys.size()) == 1'000'000) break;
}
int K = int(keys.size());
for (int i = 0; i < Q; i++) {
bool type = gen.uniform_bool();
if (!type) {
long long key = keys[i % K];
long long val = gen.uniform(0LL, K_AND_V_MAX);
printf("0 %lld %lld\n", key, val);
} else {
long long key = keys[i % K];
printf("1 %lld\n", key);
}
}
return 0;
}