Filter
Time limit1sMemory limit256 MB
The program checks each Bloom filter against every queried user id and lists the files that may hold at least one of them.
- Level
Easy2 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
A database engine named ICPC (Instant Compression and Processing Codec) stores user activity records. Every record carries one integer user identifier. The records live in compressed data files, and one file can hold records of many users. Decompressing a file costs a lot of CPU time, so before it reads a file the engine needs a cheap check that decides whether the file might hold a record of a given user.
The engine runs that check with a Bloom filter. Each database fixes these integer parameters:
- : the number of bits in a filter,
- : the number of hash functions,
- for : the multiplier of hash function .
Every data file has one filter value, a vector of bits. Bit of that vector () is one if and only if the file holds a record of some user identifier for which
holds for some hash function ().
The file may hold a record of user identifier if and only if bit of its filter value is one for every ().
You are given the filter parameters, the filter value of each data file, and a query set of user identifiers. Report every data file that may hold a record of at least one identifier in the query set.
Input
The first line contains the filter parameters , , and for (, , ).
The second line contains an integer , the number of data files (). Each of the next lines contains the filter value of one data file in hexadecimal, a string of exactly characters taken from 0123456789abcdef. The first character carries bits 0 to 3 of the value, ordered from the least significant bit of the hexadecimal digit to its most significant bit. The second character carries bits 4 to 7, the third carries bits 8 to 11, and so on. When , the last character carries the remaining bits in its least significant bits and its other bits are zero.
The next line contains an integer , the number of user identifiers in the query (), followed by the distinct identifiers of the query ().
Output
Print on one line the integer , the number of data files that may hold a record of at least one identifier of the query, followed by the zero-based numbers () of those files in increasing order. Separate every number on the line with a single space. When , print only .