玄学求解
查看原帖
玄学求解
685839
gxcgjy楼主2023/10/28 11:45
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
using namespace std;
typedef long long ll;
ll T,n,mod = 100010,maxx,tot = 0,A[1000010];
vector<ll> hashh[100011];
ll check(ll val){
	ll tt,tot,k,i,j;
	tt = (val % mod + mod) % mod;//哈希,+mod解决下标为负数的问题
	maxx = max(maxx,tt);
	for(i = 0;i < hashh[tt].size();i++){
		if(hashh[tt][i] == val) return 1;
	}
	hashh[tt].push_back(val);
	return 0;
}
int main(){
	ll i,j,k;
	scanf("%lld",&T);
	while(T--){
		scanf("%lld",&n);
		tot = 0;
		for(i = 0;i <= maxx;i++) hashh[i].clear();
		for(i = 1;i <= n;i++){
			scanf("%lld",&k);
			if(check(k) == 0) A[++tot] = k;
		} 
		for(j = 1;j <= tot;j++) printf("%lld ",A[j]);
		printf("\n");
	}
}

格式化输入输出 + 哈希 + 存到数组 = AC 哈希 + 直接输出 = TLE

2023/10/28 11:45
加载中...