Cod sursa(job #1038850)

Utilizator gener.omerGener Omer gener.omer Data 22 noiembrie 2013 00:12:03
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.72 kb
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <iostream>

using namespace std;

#define INF (1<<29)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)

map<long long, int> m;

#define SIZE 512 * 1024
#define get_hash_SIZE (SIZE * 8)

unsigned char bitset[SIZE];

long long p1_list[] = {0, 86243, 1398269, 3021377, 20996011, 25964951};
long long p2_list[] = {0, 432611, 686049, 2922509,  321534781,  780291637};

int get_hash(long long x, long long k){
	return ((x * p1_list[k]) + (k * p2_list[k])) % (get_hash_SIZE); 
}

void set_bit(int n){
	int byte = n / 8, bit = n % 8;
	bitset[byte] |= (1<<bit);
}

int get_bit(int n){
	int byte = n / 8, bit = n % 8;
	return (bitset[byte] & (1<<bit));
}

int main()
{
	freopen("dtcsu.in", "rt", stdin); 
	freopen("dtcsu.out", "wt", stdout);
	for(int i = 0; i < 276997; ++i){
		long long x;
		cin >> x;
		m[x] = 1;
		int p1 = get_hash(x, 1);
		int p2 = get_hash(x, 2);
		int p3 = get_hash(x, 3);
		set_bit(p1);
		set_bit(p2);
		set_bit(p3);
	} 
	
	long long n;
	cin >> n;
	int ret = 0;
	for(int i = 0; i < n; ++i)
	{
		long long x;
		cin >> x;
		int p1 = get_hash(x, 1);
		int p2 = get_hash(x, 2);
		int p3 = get_hash(x, 3);
		if(get_bit(p1) && get_bit(p2) && get_bit(p3))
			if(m.find(x) != m.end())
				++ret;
	}
	
	cout << ret;
	
	return 0;
}