Pagini recente » Cod sursa (job #1055348) | Cod sursa (job #85499) | Cod sursa (job #991068) | Cod sursa (job #910488) | Cod sursa (job #1038847)
#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<int, 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){
int x;
cin >> x;
m[x] = 1;
int p1 = get_hash(x, 1);
int p2 = get_hash(x, 2);
int p3 = get_hash(x, 3);
int p4 = get_hash(x, 4);
int p5 = get_hash(x, 5);
set_bit(p1);
set_bit(p2);
set_bit(p3);
set_bit(p4);
set_bit(p5);
}
int n;
cin >> n;
int ret = 0;
for(int i = 0; i < n; ++i)
{
int x;
cin >> x;
int p1 = get_hash(x, 1);
int p2 = get_hash(x, 2);
int p3 = get_hash(x, 3);
int p4 = get_hash(x, 4);
int p5 = get_hash(x, 5);
if(get_bit(p1) && get_bit(p2) && get_bit(p3) && get_bit(p4) && get_bit(p5))
if(m.find(x) != m.end())
++ret;
}
cout << ret;
return 0;
}