Cod sursa(job #1561632)

Utilizator SilviuIIon Silviu SilviuI Data 4 ianuarie 2016 12:43:26
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <stdio.h>
#include <bitset>
#define lmax 276997
#define mod1 3666013
#define mod2 4712343
#define mod3 4756891
#define mod4 3564131

using namespace std;
typedef long long int ll;

int n,nr;
ll x;
bitset <5000010> uhash;

int hash1(ll x) { return (1LL*x*3+2)%mod1; }
int hash2(ll x) { return (1LL*x*3+5)%mod2; }
int hash3(ll x) { return (1LL*x*3+7)%mod3; }
int hash4(ll x) { return (1LL*x*3+3)%mod4; }

int main()
{
	freopen("dtcsu.in","r",stdin);
	freopen("dtcsu.out","w",stdout);
	for (int i=1;i<=lmax;i++) {
		scanf("%lld",&x); 
		uhash[hash1(x)]=1; uhash[hash2(x)]=1; uhash[hash3(x)]=1; uhash[hash4(x)]=1;
	}
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		scanf("%lld",&x);
		if (uhash[hash1(x)]==1 && uhash[hash2(x)]==1 && uhash[hash3(x)]==1 && uhash[hash4(x)]==1) nr++;
	}
	printf("%d",nr);
	return 0;
}