Cod sursa(job #3177482)

Utilizator paull122Paul Ion paull122 Data 29 noiembrie 2023 11:13:02
Problema Dtcsu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
ifstream fin("dtcsu.in");
ofstream fout("dtcsu.out");
#define HASH_BASE 264
#define HASH_SIZE1 10007

int computehash(ll x)
{
    return x % HASH_SIZE1;
}

vector<int> hashvalues[10008];

void addhash(int x)
{
    int numhash = computehash(x);
    int i=0;
    while(i<(int)hashvalues[numhash].size() && hashvalues[numhash][i]!=x)
    {
        i++;
    }
    if(i==(int)hashvalues[numhash].size())
    {
        hashvalues[numhash].push_back(x);
    }
}
int query(int x)
{
    int numhash = computehash(x);
    int i=0;
    while(i<(int)hashvalues[numhash].size() && hashvalues[numhash][i]!=x)
    {
        i++;
    }
    if(i < (int)hashvalues[numhash].size())
    {
        return 1;
    }
    return 0;
}
int main()
{
    for(int i=1;i<=276997;i++)
    {
        ll x;
        fin >> x;
        addhash(x);
    }
    int q;
    fin >> q;
    int cnt=0;
    while(q--)
    {
        int x;
        fin >> x;
        cnt += query(x);
    }
    fout << cnt;
}