#P6990. [NEERC2014] Filter

[NEERC2014] Filter

题目描述

You are working on a new high-performance database engine -- Instant Compression and Processing Codec (ICPC).(ICPC). ICPC stores user activity records. Each user activity record has an integer user identifier. The records are stored in a number of data files. Each data file is compressed and can contain records from multiple users, however ICPC has to process queries that look for a specific subsets of users. In order to do so, there has to be a way to quickly determine which data files may contain records for a specific user before attempting to decompress them, which may be a long and CPU-consuming process.

ICPC uses an algorithm called Bloom Filter. The way it is implemented in ICPC is described below. For each ICPC database the following integer parameters are chosen:

mm is the number of bits in the filter;

ff is the number of hash functions in the filter;

aia_{i} are the parameters for hash functions for 0i0 \le i

A value of the bloom filter is computed for each data file. The data file's bloom filter is a vector of mm bits. A bit number j(0j<m)j (0 \le j < m) is set to one if and only if there is a record in this data file for some user identifier uk,u_{k}, such that for some hash function i(0i<f)i (0 \le i < f) the following equality holds:

j=(ukai)j = (u_{k} · a_{i}) mod mm (1)

Your task is to implement ICPC filtering logic. You are given filter parameters and values for a number of data files and a set of user identifiers. Your task is determine which data files may contain record with at least one user identifier from the specified set. A data file may contain a record with a user identifier uku_{k} if and only if for all i(0i<f)i (0 \le i < f) all the bits jj given by equality (1) in its filter value are set to one.

输入格式

The first line of the input file contains filter parameters -- integer numbers m,fm , f , and aia_{i} for $0 \le i < f (1 \le m \le 1000 , 1 \le f \le 100 , 1 \le a_{i} < 2^{31}).$

The second line of the input file contains an integer nn -- the number of data files (1n1000)(1 \le n \le 1000) . Each of the following nn lines contains bloom filter value of the corresponding file in hexadecimal form. Each value is represented by a string of m/4⌈m/4⌉ hexadecimal digits (one of 0123456789abcdef).0123456789abcdef). The first digit of the string represents bits 030-3 of the value (stored in order from the least significant bit of a hexadecimal digit to the most significant bit), the second digit -- bits 474-7 , the third -- 8118-11 , etc. When mm mod 404 ≠ 0 , then the last hexadecimal digit represents the last mm mod 44 bits of the value in its least significant bits.

The following line of the input file contains an integer qq -- the number of user identifiers in a query (1q1000)(1 \le q \le 1000) , followed by qq integers uku_{k} -- the set of distinct user identifiers in the query (1uk<231).(1 \le u_{k} < 2^{31}).

输出格式

Write a line with the integer number ss to the output file -- the number of data files that may contain a record with at least one user identifier from the specified set, followed by ss numbers dt(0dt<n)d_{t} (0 \le d_{t} < n) -- the 0based0-based numbers of the corresponding data files in ascending order.

23 4 3 5 7 11
3
effde7
c07902
0800c1
3 2 4 6

2 0 2

提示

Time limit: 1 s, Memory limit: 256 MB.