建议加强数据 时间太“松”了
查看原帖
建议加强数据 时间太“松”了
552387
DeltaCR楼主2024/8/16 10:17

谁知道我时间挂了多少回!

模数从 10610^6 换到 105,104,3×104,99997......10^5,10^4,3\times10^4,99997......

开始用 std::vector 换成 std::list,后来手写链表,手写链式前向星……

输入输出用的 std::cin/std::cout 后来改作 scanf 和 printf 还是不行,最后快读也不行!

你问我怎么改对的?

-把 std::endl 改成 '\n' AC 了!?

分数: 60,90,70,60,40,0,90,90,70,70,70,60,60,60,60,60,10060,90,70,60,40,0,90,90,70,70,70,60,60,60,60,60,100

建议加强数据。

#include <iostream>
using namespace std;

const int N = 5e4;

namespace HASH
{
    typedef unsigned long long ULL;
    const ULL MOD = 1e5 + 7;

    int head[MOD + 5];
    int nxt[N + 5], ver[N + 5], etot, vtot;
    long long hs[N + 5];

    inline int get_hash(long long x)
    {
        return (x % MOD + MOD) % MOD;
    }

    void add_edge(int u, int v, long long w)
    {
        ver[++etot] = v;
        nxt[etot] = head[u];
        hs[etot] = w;
        head[u] = etot;
    }

    void insert(long long x)
    {
        add_edge(get_hash(x), ++vtot, x);
    }

    bool find(long long x)
    {
        int val = get_hash(x);
        for (int i = head[val]; i; i = nxt[i])
            if (hs[i] == x)
                return true;
        return false;
    }

    void clear()
    {
        for (int i = 0; i <= MOD; ++i) head[i] = 0;
        etot = vtot = 0;
    }
}

int main()
{
    ios::sync_with_stdio(false);

    int t;
    cin >> t;

    while (t--)
    {
        int n;
        cin >> n;

        HASH::clear();
        for (int i = 1; i <= n; ++i)
        {
            long long x;
            cin >> x;

            if (!HASH::find(x))
            {
                HASH::insert(x);
                cout << x << " ";
            }
        }

        cout << '\n';
    }
    

    return 0;
}
2024/8/16 10:17
加载中...