Cod sursa(job #1032784)

Utilizator fmins123FMI No Stress fmins123 Data 16 noiembrie 2013 01:43:24
Problema Dtcsu Scor Ascuns
Compilator cpp Status done
Runda Marime 1.7 kb
#include <fstream>
#include <algorithm>
#include <string>
#include <bitset>
#include <vector>
#include <functional>

using namespace std;

int Q;
char num[32];
bitset< (1<<16) > bitArray[3];
bitset< (1<<15) > finalBitArray;

inline int hash1(const long long &x) {
	return x & ((1LL << 16) - 1);
}

inline int hash2(const long long &x) {
	return x >>	16LL & ((1LL << 16) - 1);
}

inline int hash3(const long long &x) {
	return x >>	32LL & ((1LL << 16) - 1);
}

inline int hash4(const long long &x){
	return x >>	48LL & ((1LL << 15) - 1);
}

vector< function<int(int)> > hashFunction;

inline void init() {
	hashFunction.push_back(hash1);
	hashFunction.push_back(hash2);
	hashFunction.push_back(hash3);
}

inline bool query(const long long &x) {
	for (int k = 0;k < 3;k++) {
		if (bitArray[k][hashFunction[k](x)] == false) {
			return false;
		}
	}
	return finalBitArray[hash4(x)];
}

inline void update(const long long &x) {
	for (int k = 0;k < 3;k++) {
		bitArray[k][hashFunction[k](x)] = true;
	}
	finalBitArray[hash4(x)] = true;
}

inline void readSet() {
	for (int i = 0;i < 276997;i++) {
		fgets(num,32,stdin);
		long long value = 0;
		for(int i = 0;num[i] && num[i] != '\n';i++) {
			value = value*10 + (num[i] - '0');
		}
		update(value);
	}
}

inline void solve() {
	int ret = 0;
	scanf("%d\n",&Q);
	for (int i = 0;i < Q;i++) {
		fgets(num,32,stdin);
		long long value = 0;
		for(int i = 0;num[i] != '\0' && num[i] != '\n';i++) {
			value = value * 10 + (num[i] - '0');
		}

		ret += query(value);
	}
	printf("%d\n",ret);
}

int main()
{
	freopen("dtcsu.in","r",stdin);
	freopen("dtcsu.out","w",stdout);
	init();
	readSet();
	solve();
	return 0;
}