luogu#P7738. [NOI2021] 量子通信

    ID: 7114 远端评测题 2500ms 384MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2021NOIO2优化鸽笼原理位运算bitset

[NOI2021] 量子通信

Background

Due to differences in judging performance, the time limit for this problem is increased by 0.5 s.

Problem Description

Little Z is teaching himself knowledge about quantum computers. Recently, he has been studying the chapter on quantum communication and encountered an interesting problem. In this problem, Alice and Bob are doing quantum communication. Their communication language is a dictionary SS of size nn. In this dictionary, each word sis_i (1in1 \le i \le n) can be represented by a 256\boldsymbol{256}-bit 01\boldsymbol{01} string. In this problem, sis_i can be generated by calling the function gen. You can view it in gen.cpp under the problem directory. The parameters n, a1, and a2 of this function will be given by the input.

Alice and Bob will then communicate mm times. In each communication, Alice transmits exactly one word from the dictionary to Bob. However, the channel they use is unreliable and will be affected by noise. More specifically, for the ii-th transmission, let the original word transmitted by Alice be xix_i. This 0101 string will be affected by noise and have at most ki\boldsymbol{k_i} bits flipped. In other words, let the 0101 string received by Bob this time be yiy_i. Compared with xix_i, it may differ in up to kik_i bits, and yiy_i may not appear in the dictionary SS.

At the same time, Bob learns that the bad guy Eve has also infiltrated their communication channel and is preparing to interfere with their communication. His method is to change the 0101 string received by Bob into an arbitrary 256256-bit 0101 string, and this string may not appear in the dictionary SS. Eve is very cunning: he does not necessarily interfere with every communication.

Now Bob asks you for help. For each upcoming communication, you need to determine, based on the final 0101 string received by Bob and the noise threshold kik_i (0ki150 \le k_i \le 15) for this communication, whether it is possible that this communication was not interfered with by Eve (that is, the 0101 string received by Bob can be obtained by flipping at most kik_i bits of some word in the dictionary). If it is possible that Eve did not interfere, output 11; otherwise output 00. Bob trusts your ability very much, so you must answer online. See the input format for the specific requirements.

To reduce input time, the string received by Bob will be given as a length 64\boldsymbol{64} hexadecimal string. The hexadecimal string contains digit characters 09\texttt{0} \sim \texttt{9} and uppercase letters AF\texttt{A} \sim \texttt{F}, where AF\texttt{A} \sim \texttt{F} represent the values 101510 \sim 15 respectively.

A hexadecimal string can be converted bit by bit into a 0101 string. For example, 5 corresponds to 0101, A corresponds to 1010, and C corresponds to 1100.

Input Format

The first line contains four non-negative integers n,m,a1,a2n, m, a_1, a_2, representing the dictionary size, the number of communications, and the initial values of parameters a1 and a2 in the gen function.

You need to call the gen function mentioned in the description in your program to generate the dictionary. You may copy and use the code in gen.cpp. The boolean array s[N+1][256] in the program contains all words.

In the next mm lines, each line contains a hexadecimal string of length 6464 and a non-negative integer kik_i, representing the 0101 string finally received by Bob in the ii-th communication and the noise threshold.

To force contestants to answer queries online, after restoring the 256-bit 0101 string from the hexadecimal string, you must XOR each bit of the 0101 string with lastans{\mathit{lastans}} to obtain the real 0101 string received by Bob in this communication, where lastans{0,1}{\mathit{lastans}} \in \{ 0, 1 \} is the answer to the previous query. Before the first query, lastans{\mathit{lastans}} is initialized to 0.

Note: When using scanf and printf to read or output variables of type unsigned long long, the corresponding format specifier is llu.

Output Format

Output mm lines. Each line contains an integer 00 or 11 indicating the answer to the current query.

见附件中的 qi/qi1.in
见附件中的 qi/qi1.ans
见附件中的 qi/qi2.in
见附件中的 qi/qi2.ans
见附件中的 qi/qi3.in
见附件中的 qi/qi3.ans

Hint

[Query Example]

To make the statement easier to explain, we give an example in a simplified setting by directly providing the words in the dictionary, reducing the word length to 4, and allowing offline queries.

Consider a dictionary of size n=2n = 2, with words 1010 and 0111.

For the query B = 1011 and k1=1k_1 = 1, the answer should be 11, because it can be obtained by flipping the 4-th bit of 1010 (from high to low bits, same below).

For the query 1 = 0001 and k2=2k_2 = 2, the answer should be 11, because it can be obtained by flipping the 2-nd and 3-rd bits of 0111.

For the query 1 = 0001 and k3=1k_3 = 1, the answer should be 00.

  • By flipping at most 1 bit of 1010, we can obtain 1010, 0010, 1110, 1000, 1011.
  • By flipping at most 1 bit of 0111, we can obtain 0111, 1111, 0011, 0101, 0110.
  • We cannot obtain 1 = 0001, so it must be caused by Eve’s interference.

[Constraints]

For all test points: 1n4×1051 \le n \le 4 \times {10}^5, 1m1.2×1051 \le m \le 1.2 \times {10}^5, 0ki150 \le k_i \le 15, and a1a_1 and a2a_2 are uniformly randomly generated in [0,2641][0, 2^{64} - 1].

Test Point ID n=n = m=m = kik_i \le Special Property
11 1010 22 None
22 500500 1515
33 10001000 00
44 20002000 22
55 50005000 1515
66 10410^4
77 2×1042\times 10^4
88 10510^5 11
99 4×1054\times 10^5 1.2×1051.2\times 10^5
1010 5×1045\times 10^4 22
1111 7×1047\times 10^4 33
1212 10510^5 22
1313 3×1043\times 10^4 55
1414 6×1046\times 10^4 44
1515 1.2×1051.2\times 10^5 55
1616 6×1046\times 10^4 88 All query strings are generated randomly
1717 1.2×1051.2\times 10^5 1212
1818 4×1054\times 10^5 10510^5 1515
1919 3×1043\times 10^4 77 None
2020 6×1046\times 10^4 99
2121 9×1049\times 10^4 1111
2222 2×1052\times 10^5 1.2×1051.2\times 10^5 1212
2323 4×1054\times 10^5 8×1048\times 10^4 1515
2424 10510^5
2525 1.2×1051.2\times 10^5

Translated by ChatGPT 5