Pagini recente » Istoria paginii utilizator/robydario | Monitorul de evaluare | Cod sursa (job #2157777) | Profil Bogdacutu | Cod sursa (job #1034016)
#include <cstdio>
#include <bitset>
using namespace std;
template<const int Size, const int nrHash>
class BloomFilter{
unsigned char B[1 + (Size >> 3)];
inline void setBit(unsigned long long x){
x &= Size;
B[x >> 3] |= 1 << (x & 7);
}
inline bool getBit(unsigned long long x){
x %= Size;
return B[x >> 3] & ( 1 << (x & 7) );
}
public:
void update(unsigned long long x){
int times = nrHash;
while (times--){
setBit(x);
x >>= 1;
}
}
bool query(unsigned long long x){
int times = nrHash;
while (times--){
if (!getBit(x))
return false;
x >>= 1;
}
return true;
}
};
BloomFilter<5607389, 60> B;
const int buffSize = 1 << 17;
char buff[buffSize];
int main(){
int times = 276997, ans = 0;
long long x;
FILE* in = fopen("dtcsu.in", "r");
FILE* out = fopen("dtcsu.out", "w");
setvbuf(in, buff, _IOFBF, buffSize);
while (times--){
fscanf(in, "%lld", &x);
B.update(x);
}
/*
fscanf(in, "%d", times);
while (times--){
fscanf(in, "%lld", &x);
ans += B.query(x);
}
*/
fprintf(out, "%d\n", ans);
return 0;
}