版本比较
题解:P11615 【模板】哈希表
正文
增加 21 行删除 21 行
10 行未改动1112131415161718196 行未改动262728293031323334353626 行未改动636465666768697071727314 行未改动888990919293949596979810 行未改动10911011111211311411511611711811914 行未改动1341351361371381391401411421431441451461471481491501511521534 行未改动15815916016116216316416516616716816917017117217317417517617717 行未改动10 行未改动const int SZ = 1 << 18; char *p1, *p2, buf[SZ];#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, SZ, stdin), p1 == p2) ? EOF : *p1++)#endifinline void skip() {for (char ch = getchar(); ch == ' ' || ch == '\n' || ch == '\t'; ch = getchar());}int t; char ch;template <typename T> inline void read(T& x) {x = 0, t = 1, ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') t = -1; for (; '0' <= ch && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48); x *= t;}inline void read(char& x) {skip(), x = getchar();}template <typename T, typename... Args> inline void read(T& t, Args&... args) {read(t); read(args...);}6 行未改动const int M = 5000011;struct Hash {map<uint64, uint64> a[M];int h(uint64 x) {return x % M;}uint64 get(uint64 x);void set(uint64 x, uint64 y);} mp;26 行未改动int next;uint64 x, y;} edge[M];int tot = 0, head[M];int h(uint64 x) {return x % M;}uint64 get(uint64 x) {for (int j = head[h(x)]; j != 0; j = edge[j].next) {if (edge[j].x == x) return edge[j].y;}14 行未改动```cppstruct Hash {map<uint64, uint64> a[M];int h(uint64 x) {return x % M;}uint64 get(uint64 x) {return a[h(x)][x];}void set(uint64 x, uint64 y) {10 行未改动```cppstruct Hash {vector<pair<uint64, uint64>> a[M];int h(uint64 x) {return x % M;}uint64 get(uint64 x) {for (const auto& i : a[h(x)]) {if (i.first == x) return i.second;}14 行未改动```cppstruct Hash {pair<uint64, uint64> a[M];int h(uint64 x) {return x % M;}uint64 get(uint64 x) {int i = h(x), j = 1;for (; a[i].first != x && a[i].second != 0; j++) i = (i + j) % M;a[i].first = x;return a[i].second;}void set(uint64 x, uint64 y) {int i = h(x), j = 1;for (; a[i].first != x && a[i].second != 0; j++) i = (i + j) % M;a[i].first = x, a[i].second = y;}} mp;```4 行未改动```cppstruct Hash {pair<uint64, uint64> a[M];int h(uint64 x) {return x % M;}uint64 get(uint64 x) {int i = h(x), j = 1;for (; a[i].first != x && a[i].second != 0; j++) i = (i + j * j) % M;a[i].first = x;return a[i].second;}void set(uint64 x, uint64 y) {int i = h(x), j = 1;for (; a[i].first != x && a[i].second != 0; j++) i = (i + j * j) % M;a[i].first = x, a[i].second = y;}} mp;```17 行未改动10 行未改动1112131415161718196 行未改动262728293031323334353626 行未改动636465666768697071727314 行未改动888990919293949596979810 行未改动10911011111211311411511611711811914 行未改动1341351361371381391401411421431441451461471481491501511521534 行未改动15815916016116216316416516616716816917017117217317417517617717 行未改动10 行未改动const int SZ = 1 << 18; char *p1, *p2, buf[SZ];#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, SZ, stdin), p1 == p2) ? EOF : *p1++)#endifinline void skip() {for (char ch = getchar(); ch == ' ' || ch == '\n' || ch == '\t'; ch = getchar());}int t; char ch;template <typename T> inline void read(T& x) {x = 0, t = 1, ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') t = -1; for (; '0' <= ch && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48); x *= t;}inline void read(char& x) {skip(), x = getchar();}template <typename T, typename... Args> inline void read(T& t, Args&... args) {read(t); read(args...);}6 行未改动const int M = 5000011;struct Hash {map<uint64, uint64> a[M];int h(uint64 x) {return x % M;}uint64 get(uint64 x);void set(uint64 x, uint64 y);} mp;26 行未改动int next;uint64 x, y;} edge[M];int tot = 0, head[M];int h(uint64 x) {return x % M;}uint64 get(uint64 x) {for (int j = head[h(x)]; j != 0; j = edge[j].next) {if (edge[j].x == x) return edge[j].y;}14 行未改动```cppstruct Hash {map<uint64, uint64> a[M];int h(uint64 x) {return x % M;}uint64 get(uint64 x) {return a[h(x)][x];}void set(uint64 x, uint64 y) {10 行未改动```cppstruct Hash {vector<pair<uint64, uint64>> a[M];int h(uint64 x) {return x % M;}uint64 get(uint64 x) {for (const auto& i : a[h(x)]) {if (i.first == x) return i.second;}14 行未改动```cppstruct Hash {pair<uint64, uint64> a[M];int h(uint64 x) {return x % M;}uint64 get(uint64 x) {int i = h(x), j = 1;for (; a[i].first != x && a[i].second != 0; j++) i = (i + j) % M;a[i].first = x;return a[i].second;}void set(uint64 x, uint64 y) {int i = h(x), j = 1;for (; a[i].first != x && a[i].second != 0; j++) i = (i + j) % M;a[i].first = x, a[i].second = y;}} mp;```4 行未改动```cppstruct Hash {pair<uint64, uint64> a[M];int h(uint64 x) {return x % M;}uint64 get(uint64 x) {int i = h(x), j = 1;for (; a[i].first != x && a[i].second != 0; j++) i = (i + j * j) % M;a[i].first = x;return a[i].second;}void set(uint64 x, uint64 y) {int i = h(x), j = 1;for (; a[i].first != x && a[i].second != 0; j++) i = (i + j * j) % M;a[i].first = x, a[i].second = y;}} mp;```17 行未改动