Pagini recente » Cod sursa (job #1513044) | Cod sursa (job #2412917) | Cod sursa (job #2591556) | Cod sursa (job #1964576) | Cod sursa (job #1033944)
#include <cstdio>
#include <bitset>
using namespace std;
template<const int Size, const int nrHash>
class BloomFilter{
bitset<Size> B;
public:
void update(unsigned long long x){
int times = nrHash;
while (times--){
B[x % Size] = true;
x <<= 1;
}
}
bool query(unsigned long long x){
int times = nrHash;
while (times--){
if (!B[x % Size])
return false;
x <<= 1;
}
return true;
}
};
BloomFilter<6948437, 60> B;
const int buffSize = 1 << 17;
char buff[buffSize];
int main(){
FILE* in = fopen("dtcsu.in", "r");
FILE* out = fopen("dtcsu.out", "w");
setvbuf(in, buff, _IOFBF, buffSize);
int times = 276997;
long long x;
while (times--){
fscanf(in, "%lld", &x);
B.update(x);
}
int ans = 0;
fscanf(in, "%d", times);
while (times--){
fscanf(in, "%lld", &x);
ans += B.query(x);
}
fprintf(out, "%d\n", ans);
return 0;
}