求助,为什么hash换一个值就RE了
查看原帖
求助,为什么hash换一个值就RE了
615348
zesqwq楼主2022/9/2 10:21
#include <bits/stdc++.h>
using namespace std;
const int SIZ = 9999991, N = 1e6 + 10;
struct Map {
    struct Point {
        int u, v, nxt;
    } data[N];
    int tot, h[SIZ];
    inline int hash(int x) { return x % SIZ; }
    inline int &operator[](int x) {
        int hu = hash(x);
        for (int i = h[hu]; i; i = data[i].nxt)
            if (data[i].u == x) return data[i].v;
        return data[++tot] = {x, -1, h[hu]}, h[hu] = tot, data[tot].v;
    }
    Map() { tot = 0, memset(h, 0, sizeof(h)); }
    inline void clear() {
        if (tot > SIZ)
            tot = 0, memset(h, 0, sizeof(h));
        else {
            for (int i = 1; i <= tot; i++) h[hash(data[i].u)] = 0;
            tot = 0;
        }
    }
} mp;
int T, n;
int f[N], cnt;
int main() {
    cin >> T;
    int a;
    while (T--) {
        scanf("%d", &n);
        mp.clear();
        cnt = 0;
        for (int i = 1; i <= n; i++) {
            scanf("%d", &a);
            if (!(~mp[a])) f[++cnt] = a, mp[a] = 1;
        }
        for (int i = 1; i <= cnt; i++) printf("%d ", f[i]);
        putchar('\n');
    }
    return 0;
}

rt

SIZ=999991时可以通过, SIZ=9999991时无法通过

帮忙看一下何处写挂了

2022/9/2 10:21
加载中...