#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAX 1000010
#define mod 1000007
int head[MAX],cnt;
struct edge
{
int x;
int cnt;
int next;
}edg[MAX];
void add(int x)
{
int mid = x%mod;
for (int i = head[mid]; i != -1; i = edg[i].next)
{
if (x == edg[i].x)
{
edg[i].cnt++;
return;
}
}
edg[cnt].x = x;
edg[cnt].next = head[mid];
edg[cnt].cnt = 1;
head[mid] = cnt++;
}
int Scan()//读入外挂
{
int res = 0, ch, flag = 0;
if ((ch = getchar()) == '-') //判断正负
flag = 1;
else if (ch >= '0' && ch <= '9') //得到完整的数
res = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9')
res = res * 10 + ch - '0';
return flag ? -res : res;
}
int getb(int x)
{
int mid = x%mod;
for (int i = head[mid]; i != -1; i = edg[i].next)
{
if (x == edg[i].x)
{
int v=edg[i].cnt;
edg[i].cnt = 0;
return v;
}
}
return 0;
}
int main()
{
int n, k;
while (~scanf("%d%d", &n, &k))
{
int x;
cnt = 0;
memset(head, -1, sizeof(head));
while (n--)
{
x = Scan();
add(x);
}
while (k--)
{
x = Scan();
printf("%d\n", getb(x));
}
}
}
【BestCoder】36 B Gunner(哈希)
最新推荐文章于 2015-09-28 21:26:26 发布