#P15652. [省选联考 2026] 排列游戏
[省选联考 2026] 排列游戏
Background
This is an interactive problem.
Submission notes:
- Do not include the header file
perm.h. - Paste the following at the top of your file:
#include <vector> void init(int, int); std::vector<int> perm(int); int query(int, int); - Submit using C++ 17 / 20.
Problem Description
Xiao H and Xiao L are playing a game of guessing a permutation.
Xiao H has a permutation of . Now Xiao L knows the length of the permutation, and he wants to guess this permutation through a special kind of queries. Specifically, Xiao L can ask Xiao H queries of the following form:
- Given non-negative integers satisfying , find the smallest non-negative integer that does not appear in .
However, Xiao H and Xiao L found that even with infinitely many queries, sometimes it is still impossible to uniquely determine the permutation . So they agree on the following: suppose Xiao H’s answer is , and Xiao L’s guessed permutation is . If for any , the smallest non-negative integer missing from the interval is always equal to the smallest non-negative integer missing from the interval , then Xiao L’s guess is considered correct.
To make the game harder, Xiao H limits the number of queries Xiao L can make. You need to help Xiao L guess Xiao H’s permutation.
Implementation Details
Contestants do not need to, and should not, implement the main function.
Contestants need to make sure the submitted program includes the header file perm.h, i.e., add the following at the beginning of the program:
#include "perm.h"
In the submitted source file perm.cpp, contestants need to implement the following two functions:
void init(int c, int t);
- denote the test point ID and the number of testdata groups, respectively. means this test point is the sample.
- For each test point, this function will be called by the interactive library exactly once when the program starts running.
std::vector<int> perm(int n);
- is the length of the permutation.
- This function should return a permutation of , representing Xiao L’s guess.
- For each test point, this function will be called by the interactive library exactly times.
Contestants can make one query by calling the following function:
int query(int l, int r);
- specify the query interval. Contestants must ensure .
- This function returns the smallest non-negative integer that does not appear in .
- Contestants must ensure that each time the interactive library calls
perm, the number of calls to this function does not exceed .
Note: In all cases, the interactive library used in the final tests will take no more than seconds to run, and it uses a fixed amount of memory, which is no more than MiB.
How to Run the Tester
grader.cpp in the problem directory is a reference implementation of the interactive library. The interactive library used in the final tests is different from this reference implementation, so your solution should not rely on the library implementation.
You can compile an executable in the problem directory using the following command:
g++ grader.cpp perm.cpp -o perm -std=gnu++14 -O2 -static
Input Format
For the compiled executable:
- The executable will read input from standard input in the following format:
- The first line contains two non-negative integers , which are the test point ID and the number of testdata groups.
- Then follow testdata groups. For each testdata group:
- The first line contains a positive integer , the length of the permutation.
- The second line contains non-negative integers , which is Xiao H’s permutation.
Output Format
- The executable will output to standard output in the following format:
- For each testdata group:
- The first line contains a string indicating the result. Specifically,
Correctmeans the contestant’s returned result is correct;Wrong answermeans the contestant’s returned result is incorrect;Invalid operationmeans the contestant’s call toqueryis invalid.
- If the result is
Correct, then the second line contains a non-negative integer, which is the maximum number of calls toqueryamong all testdata groups.
- The first line contains a string indicating the result. Specifically,
- For each testdata group:
0 1
6
4 2 3 5 0 1
Correct.
4
Hint
Sample 1 Explanation
This sample contains one testdata group.
For the first testdata group, Xiao H’s permutation is .
Here is one possible interaction process:
- Call
query(0, 3), and the interactive library returns the smallest non-negative integer missing from , which is . - Call
query(3, 4), and the interactive library returns the smallest non-negative integer missing from , which is . - Call
query(1, 5), and the interactive library returns the smallest non-negative integer missing from , which is . - Call
query(3, 5), and the interactive library returns the smallest non-negative integer missing from , which is . - Return .
It can be proven that the permutation is considered correct.
Sample 2
See perm/perm2.in and perm/perm2.ans in the contestant directory.
This sample satisfies the constraints of test points .
Notes on Provided Files
In this problem directory:
grader.cppis the provided reference implementation of the interactive library.perm.his the header file; contestants do not need to care about its specific contents.template_perm.cppis the provided sample code, which contestants can refer to and use to implement their own code.
Contestants should back up all provided files. During final evaluation, only perm.cpp in this problem directory will be tested. Any changes to files other than this program will not affect the evaluation results.
Constraints
For all testdata:
- .
- .
- For all , we have , and is a permutation of .
::cute-table{tuack}
| Test Point ID | Special Property | |
|---|---|---|
| None | ||
| A | ||
| ^ | B | |
| C | ||
| None |
- Special property A: .
- Special property B: There exists a non-negative integer such that is monotonically decreasing, and is monotonically increasing.
- Special property C: is generated independently and uniformly at random among all permutations of .
Scoring
Note:
- Contestants must not obtain internal information from the interactive library by illegal means, such as directly interacting with standard input/output streams. Such behavior will be considered cheating.
- The interactive library used in the final evaluation is different from the sample interactive library.
This problem will first be subject to the same limits as traditional problems, e.g., compilation errors will cause the whole problem to score points, runtime errors, time limit exceeded, memory limit exceeded, etc. will cause the corresponding test points to score points. Contestants may only access variables they define and variables provided by the interactive library; attempting to access other address spaces may cause compilation errors or runtime errors.
Each time the perm function is called, if the returned permutation is not considered correct, or if the call to query is invalid, or if the number of calls to query exceeds , then the corresponding test point scores points.
On top of the above conditions:
- For test points , the program gets full score if and only if, each time
permis called, the number of calls toquerydoes not exceed . - For test points , let be the maximum number of queries per call to
perm. The program will receive points, where is computed as follows:
::cute-table{tuack} | | | |:-:|:-:| | | | | | | | | | | | |
- For test points , let be the maximum number of queries per call to
perm. The program will receive points, where is computed as follows:
::cute-table{tuack} | | | |:-:|:-:| | | | | | | | | | | | |
Translated by ChatGPT 5