luogu#P7738. [NOI2021] 量子通信
[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 of size . In this dictionary, each word () can be represented by a -bit string. In this problem, 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 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 -th transmission, let the original word transmitted by Alice be . This string will be affected by noise and have at most bits flipped. In other words, let the string received by Bob this time be . Compared with , it may differ in up to bits, and may not appear in the dictionary .
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 string received by Bob into an arbitrary -bit string, and this string may not appear in the dictionary . 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 string received by Bob and the noise threshold () for this communication, whether it is possible that this communication was not interfered with by Eve (that is, the string received by Bob can be obtained by flipping at most bits of some word in the dictionary). If it is possible that Eve did not interfere, output ; otherwise output . 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 hexadecimal string. The hexadecimal string contains digit characters and uppercase letters , where represent the values respectively.
A hexadecimal string can be converted bit by bit into a 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 , 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 lines, each line contains a hexadecimal string of length and a non-negative integer , representing the string finally received by Bob in the -th communication and the noise threshold.
To force contestants to answer queries online, after restoring the 256-bit string from the hexadecimal string, you must XOR each bit of the string with to obtain the real string received by Bob in this communication, where is the answer to the previous query. Before the first query, 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 lines. Each line contains an integer or 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 , with words 1010 and 0111.
For the query B = 1011 and , the answer should be , 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 , the answer should be , because it can be obtained by flipping the 2-nd and 3-rd bits of 0111.
For the query 1 = 0001 and , the answer should be .
- By flipping at most 1 bit of
1010, we can obtain1010,0010,1110,1000,1011. - By flipping at most 1 bit of
0111, we can obtain0111,1111,0011,0101,0110. - We cannot obtain
1 = 0001, so it must be caused by Eve’s interference.
[Constraints]
For all test points: , , , and and are uniformly randomly generated in .
| Test Point ID | Special Property | |||
|---|---|---|---|---|
| None | ||||
| All query strings are generated randomly | ||||
| None | ||||
Translated by ChatGPT 5