Cod sursa(job #2475138)

Utilizator DawlauAndrei Blahovici Dawlau Data 16 octombrie 2019 12:12:07
Problema Dtcsu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.38 kb
//#include "pch.h"
#include <fstream>
#include <vector>

using namespace std;

class InParser {

private:

	static const int buffSZ = (1 << 15);
	ifstream File;
	int buffPos;
	char buff[buffSZ];

	void _advance() {

		if (++buffPos == buffSZ) {

			File.read(buff, buffSZ);
			buffPos = 0;
		}
	}

public:

	InParser(const char *FileName) {

		File.open(FileName);
		buffPos = buffSZ - 1;
	}

	InParser& operator >>(long long &no) {

		while (!isdigit(buff[buffPos]))
			_advance();
		no = 0;
		while (isdigit(buff[buffPos])) {

			no = no * 10 + buff[buffPos] - '0';
			_advance();
		}

		return *this;
	}
};

class HashMap {

	private:

		static const int Mod = 666013;
		vector <long long> hash[Mod];

	public:

		HashMap() {}

		bool search(const long long &val) {

			long long key = val % Mod;
			for (const long long &itm : hash[key])
				if (itm == val)
					return true;
			return false;
		}

		void add(const long long &val) {

			if (search(val))
				return ;
			hash[val % Mod].push_back(val);
		}
}hashmap;

InParser fin("dtcsu.in");
ofstream fout("dtcsu.out");

int main() {

	for (int x = 276997; x; --x) {

		long long no;
		fin >> no;

		hashmap.add(no);
	}

	long long Q;
	fin >> Q;

	int cnt = 0;
	for (; Q; --Q) {

		long long no;
		fin >> no;

		if (hashmap.search(no)) ++cnt;
	}

	fout << cnt;
}