现在的位置: 首页 > 综合 > 正文

【wikioi1230】 元素查找

2018年01月13日 ⁄ 综合 ⁄ 共 380字 ⁄ 字号 评论关闭
#include<cstdio>
#include<cstring>
using namespace std;
int n,m,hs[100007];
bool pd[100007];
int hash(int x){
	int t=x%100007;
	while(pd[t]&&hs[t]!=x)t=(t+1)%100007;
	pd[t]=1;
	return t;
}
int main(){
	memset(pd,0,sizeof(pd));
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++){
		int t;scanf("%d",&t);
		hs[hash(t)]=t;
	}
	for(int i=1;i<=m;i++){
		int t;scanf("%d",&t);
		if(hs[hash(t)]==t)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

抱歉!评论已关闭.