#P3782. [WC2017] 排序
[WC2017] 排序
Description
Niuniu has recently learned about sorting and has become very interested in the efficiency of sorting algorithms. To optimize sorting time, Niuniu turned to you at the winter camp to help design a computer to perform sorting (ascending).
The computer is designed as follows:
-
The sequence to be sorted is stored in an array of size .
-
The smallest unit of computation is a comparator, represented by a triple (all integers), where , . Its function is: at time , compare and . If , swap and ; otherwise do nothing.
-
For the computer to work (but not necessarily solve the problem), any two comparators must not conflict. Two comparators and conflict if and only if at least two numbers among are equal and . For example, comparators and do not conflict, while and do conflict.
At runtime, each comparator in the computer performs its operation at its preset time. The running time of the computer is the maximum value of parameter among all comparators; the smaller this value, the shorter the running time.
To test your computer design, Niuniu provides testdata. Each group of testdata contains queries, i.e., permutations of length . For each group of testdata, please design a computer with running time at most (otherwise the computer will time out) that can sort all in the testdata.
Input Format
To help you distinguish sub-tasks, each input file begins with an integer , the current test point index.
The second line contains an integer , the number of testdata groups in this test point.
For each group of testdata, the first line contains three integers .
Then follow lines, each containing integers describing a permutation of to .
It is guaranteed that a solution exists.
Output Format
For each group of testdata, output an integer in the first line, the number of comparators in your computer.
Then output lines, each with integers , describing a comparator of your computer.
If , then the computer cannot work.
0
1
3 5 4
1 2 5 3 4
3 4 5 1 2
3 1 4 2 5
7
1 2 1
3 4 1
2 3 2
4 5 2
1 2 3
3 4 3
2 3 4
Hint
Download input data and checker
Download from here.
Warning: All files (including the SPJ) are in Windows (64-bit) format.
About the UKE issue
Because the SPJ has high time complexity, please use as few comparators as possible. Otherwise the SPJ may TLE, causing the verdict to be UKE.
The SPJ time complexity is:
$$O\left ( \sum_{i=1}^{J}q_i\times (n_i+f_i) \right )$$Scoring
There are 8 test points with groups of testdata respectively, 100 groups in total, and each group of testdata is worth 1 point.
In each group of testdata, if and , the comparators do not conflict, and the computer can sort all in the testdata, then that testdata scores; otherwise it scores 0.
If you output fewer than computers, we assume your -th computer corresponds to the -th group of testdata.
If your output format is invalid, we do not guarantee you can get points for that test point.
Data characteristics
For of the data, , , . See the downloadable data for the rest.
Some partial characteristics:
-
Test point (10 points): For every input permutation , all its cycle sizes are pairwise distinct. You can think of a permutation of length as an undirected graph with nodes and edges (a functional graph consisting only of cycles), where there is an edge between node and node . Every connected component in this graph is a cycle (i.e., the graph consists of several cycles), e.g., $P=\{\color{blue}1,\color{green}3,2,\color{purple}6,\color{red}10,\color{purple}7,4,\color{red}5,8,9\color{black}\}$ (each color indicates a cycle).
-
Test point (19 points): For every input permutation , there exist several pairwise disjoint intervals such that after rotating each interval left by one step, the array becomes sorted, e.g., $P=\{\color{blue}3,1,2,\color{green}7,4,5,6,\color{purple}8,\color{red}9\color{black}\}$ (each color indicates an interval). Example of a left cyclic shift: rotated left by one step becomes .
-
In the first 8 groups of testdata of test point (8 points), for every input permutation , there exists an integer such that after rotating the interval left by one step, the array becomes sorted, e.g., .
Test your output
We provide a checker (Windows x64) in the files to evaluate your output. Usage:
checker.exe sort<I>.in sort<I>.out sort<I>.out
Here is the test point index (do not include angle brackets in the input), checker.exe is the checker, sort<I>.in is the provided input file, and sort<I>.out is your corresponding output file (input twice). Running this command will show your score on the input file sort<I>.in with your output file sort<I>.out.
After you invoke the program, the checker prints the result for each group of testdata, including (if multiple errors occur simultaneously, one of them is reported):
| Result | Meaning |
|---|---|
FAIL! |
Unknown error: SPJ runtime failure. |
Input error! |
Invalid input file: you modified the input. |
The number of the comparators is invalid! |
Detected . |
Unexpected EOF |
The computer you provided is incomplete. |
The running time of the comparator should be in [1, 150] |
Detected . |
Invalid sorting network! |
The computer you provided cannot work. |
The answer is incorrect |
The computer you provided cannot solve all queries. |
Invalid! m=(X) but M=(X) |
The computer timed out: (). |
Correct! m=(X) and M=(X) |
The computer is correct: (). |
Finally, if the checker finishes normally, it additionally prints Total points: (Z), which is the total points you scored on this test point.
Reminder
Please pay attention to the difference between “test point”, “testdata”, and “query”.
Please keep in mind the structure below:
-
The whole problem
-
Test point
-
Testdata
- Query
-
Testdata
- Query
-
Testdata
-
Query
-
Query
-
…
-
Query
-
-
…
-
Testdata
-
-
Test point
-
…
-
Test point
-
Translated by ChatGPT 5
京公网安备 11011102002149号