#P8988. [北大集训 2021] Datalab
[北大集训 2021] Datalab
Background
CTT2021 D2T2.
Special reminder: due to Luogu’s interactive mechanism, you cannot include datalab.h in your program. Instead, you must copy the content of datalab.h to the beginning of your file. That is, add the following lines before the solve function in your program:
#include<bitset>
#include<vector>
typedef std::bitset<8192> Bitset;
Bitset Add(Bitset A,Bitset B);
std::vector<int> solve(int k,int LIMIT);
Problem Description
This is an interactive problem.
On the AutoLab platform, there is a strange -bit computer, where is a fixed constant . The word length of this computer is exactly , and it stores integers as follows:
Each integer is stored in consecutive bits. Suppose the values of these consecutive bits, arranged in increasing index order, form a length- binary string consisting of 0 and 1. Assume is indexed starting from . Then the integer value corresponding to is , where is a length- array pre-defined by a certain little W, indexed from , and . For some special reason, this computer guarantees and . However, you do not know the values of .
Let , . Then we find that for every , there is exactly one length- binary string such that (proof omitted). Let the set of all integers in be . Then is a bijection from to . Therefore, we can define the inverse function of , and it satisfies .
Assume . Then the addition operation between two integers on this computer is defined as $x \oplus y \overset{def}{=} (x + y - L + 2^k) \bmod 2^k + L$. It is easy to see that . Thus, addition on this computer is closed. The addition defined by the above rule also satisfies commutativity, associativity, and other properties. Proofs are omitted as well.
Students can obtain information related to through a limited number of queries. In each query, you can give the computer two length- strings containing only , and the computer will return the value of . The task of this assignment is to determine the exact values of using no more than queries.
Little Z is an extremely clever student, so he tried to use his super brain of to compute each interaction result by hand. However, he found that even his processing speed could not keep up with the huge amount of data. Therefore, he asks you to write a program to help him complete this assignment faster.
Task
You do not need to, and should not, implement the main function. You only need to implement the following function:
std::vector<int> solve(int k,int m):- The input numbers are the computer word length and the query limit .
- You need to return a
vectorof size , where the -th element represents the value of you have determined.
You can call the following function to use the addition operation on AutoLab.
std::bitset<8192> Add(std::bitset<8192> x,std::bitset<8192> y):- Given two bitsets of size , reading each bitset from low bit to high bit represents a length- binary string containing only 0 and 1.
- Returns a bitset of size , representing the value of . The returned format is the same as the input format.
As required, you can query the addition result of two integers on this computer at most times. In other words, you can call the Add function at most times.
During judging, the interactive library will call solve exactly once.
This problem guarantees that the array sgn has been completely fixed before the start and will not be dynamically constructed based on the interaction with your program. Therefore, the interactive operations in this problem are deterministic, and you do not need to care about the specific implementation in the interactive library.
The testdata guarantees that under the call limit, the time required by the interactive library does not exceed 1s. The memory used by the interactive library is fixed and does not exceed 128MB.
How to test your program
grader.cpp in the problem directory is a reference implementation of the interactive library we provide. The interactive library implementation used in the final test is different from this reference implementation, so your solution should not depend on the library implementation.
-
You need to compile an executable in this directory using the following command:
g++ grader.cpp sample.cpp -o sample -O2 -lm
-
For the compiled executable:
- The executable will read the following input format from standard input:
- The first line contains two integers .
- The next line contains integers, where the -th number denotes .
- After reading, the interactive library will call the function exactly once. After your function returns correctly, the interactive library will check whether your computation is correct. If correct, it will output
Correctand information related to the number of interactive calls; otherwise, it will output the corresponding error information.
- The executable will read the following input format from standard input:
There is a reference code sample.cpp provided by the problem setter in the problem directory. Note that this code is not guaranteed to pass all test cases.
Samples 1 and 2
See the attachment download.
These two samples satisfy the input format of the executable program, so they can be directly input into the executable program.
Hint
Scoring
| subtask | ||
|---|---|---|
| 1 | ||
| 2 | ||
| 3 |
For any subtask, if the contestant returns an incorrect answer on any test case, or exceeds the query limit, the score is .
Otherwise, suppose within a subtask, the maximum number of queries used among all test points is . Then for each subtask, the contestant’s score is:
- Subtask : .
- Subtask : .
- Subtask : $\min \{75,\lfloor \frac{13800}{\max\{a,1\}} \rfloor \}$.
In other words, Subtask gets full score if and only if .
The total score for this problem is the sum of the scores of the three subtasks.
Translated by ChatGPT 5