Bloom filter · Compiler
Bloom filter
Simulate a Bloom filter of m bits, initially all zero and numbered from 0 to m - 1. The two positions for key k are k % m and floor(k / m) % m, where % is the remainder. ADD sets both bits to 1. CHECK reports MAYBE when both bits are 1, or ABSENT when either is 0. Bits stay set for all later commands.
- Input
- The first line contains m and q (1 <= m <= 50, 1 <= q <= 100). Each of the next q lines contains ADD k or CHECK k for an integer k from 0 to 10000. There is at least one CHECK.
- Output
- Print one line per CHECK containing MAYBE or ABSENT.
Compiler Explorer runs your code when you run or check it.
Loading your exercise draft…