Quantum Communication

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

Alice and Bob are engaging in quantum communication. Their language of communication is a dictionary SS of size nn. In the dictionary, a word s_is\_i (1in)(1 \le i \le n) may be represented by a 256-bit binary string. In this problem, s_is\_i may be generated by calling function gen. The contestants may refer to gen.cpp, and the parameters n,a1,a2 will be specified by the test cases.

Alice and Bob will communicate for mm rounds next. In each round, Alice will send bob exactly one word in the dictionary. However, their communication channel is not reliable and may be disturbed by noise. More formally, for the ii-th round of communication, suppose the word Alice wants to send is x_ix\_i, then at most k_ik\_i bits of the binary string will flip. In other words, suppose the binary string Bob receives is y_iy\_i, then y_iy\_i is different from x_ix\_i for at most k_ik\_i positions. y_iy\_i does not have to be in dictionary SS.

At the same time, Bob knows Eve has invaded the communication channel and is going to manipulate the communication between Alice and Bob. Eve will replace the binary string Bob is going into receive with an arbitrary 256-bit binary string, and the arbitrary 256-bit binary string does not have to be in the dictionary. Eve does not have to manipulate all rounds of communication.

Now Bob asks you for help, and you need to determine whether it is possible that a round of communication is not manipulated by Eve given the string Bob received and the threshold for noise disturbance k_ik\_i (0k_i15)(0 \le k\_i \le 15). In other words, you need to check whether the binary string Bob received can be obtained by flipping at most k_ik\_i bits of a word in the dictionary. If it is possible that the round of communication is not manipulated by Eve, output 1. Otherwise, output 0. Bob trusts your ability, so you need to answer the queries online. For the specifics, see the input section.

To save the time spent on I/O, the strings Bob received are given by 64-bit hexadecimal strings. The hexadecimal strings contain numerals 0-9 and upper-case English letters A-F. A-F represents 10-15 in that order. A hexadecimal string may be converted to a binary string bit by bit. For example, 5 will correspond to 0101A will correspond to 1010, and C will correspond to 1100.

입력

The first line of the input contains four nonnegative integers n,m,a_1,a_2n,m,a\_1,a\_2 denoting the size of the dictionary, the number of rounds of communication, and the initial values of parameters a1 and a2 for the function gen. Contestants need to generate the dictionary using the gen function mentioned in the problem statement. Contestants may copy and use the code in gen.cpp. The Boolean array s[N+1][256] is just the list of all words.

For the next mm lines, each line contains a hexadecimal string of length 64 and a nonnegative integer k_ik\_i denoting the final binary string Bob received in round ii and the threshold for noise disturbance.

To make sure contestants are answering the queries online, after the contestants recover the 256-bit binary string based on the hexadecimal string, contestants need to perform XOR operation with lastans bitwise to recover the real binary string Bob received in the round. lastans 0,1\in \\{0,1\\} denotes the answer to the query last round. Before the first round, the initial value of lastans is 0.

Notice: when reading or writing unsigned long long variables using scanf or printf, use llu.

출력

The output consists of mm lines. Each line contains an integer 0 or 1 denoting the answer to the query.

제한

For all test cases, 1n4×1051 \le n \le 4 \times 10^51m1.2×1051 \le m \le 1.2 \times 10^50k150 \le k \le 15, and a_1,a_2a\_1,a\_2 are uniformly random among \[0,2641]\[0,2^{64}-1].

Test casen=n =m=m =k_ik\_i \leAdditional Constraints
1101022None.
25005001515
31,0001\\,00000
42,0002\\,00022
55,0005\\,0001515
610,00010\\,000
720,00020\\,000
8100,000100\\,00011
9400,000400\\,000120,000120\\,000
1050,00050\\,00022
1170,00070\\,00033
12100,000100\\,00022
1330,00030\\,00055
1460,00060\\,00044
15120,000120\\,00055
1660,00060\\,00088The query strings are generated randomly.
17120,000120\\,0001212
18400,000400\\,000100,000100\\,0001515
1930,00030\\,00077None.
2060,00060\\,00099
2190,00090\\,0001111
22200,000200\\,000120,000120\\,0001212
23400,000400\\,00080,00080\\,0001515
24400,000400\\,000100,000100\\,0001515
25400,000400\\,000120,000120\\,0001515