#P8376. [APIO2022] 排列
[APIO2022] 排列
Background
This problem only supports C++ submissions. When submitting, you do not need to include the perm.h header file. You only need to paste the content of perm.h from the attachment at the beginning of your code.
Problem Description
Pharaohs use the gravity of planets to accelerate spaceships. Suppose a spaceship will fly by planets in order with orbital speeds . When flying by each planet, the Pharaoh scientists may choose whether to use it to accelerate the spaceship. To save energy, after the spaceship flies by a planet with orbital speed and accelerates, it can no longer accelerate when later flying by a planet with orbital speed . In other words, the planets chosen for acceleration form an increasing subsequence of . A subsequence of is a sequence obtained by deleting zero or more elements from . For example, , , , and are subsequences of , but is not.
The scientists have confirmed that there are a total of different ways to choose planets to accelerate the spaceship, but they have lost the record of orbital speeds (even the value of ). However, they remember that is a permutation of . Here, a permutation is a sequence that contains every integer from to exactly once. Your task is to find such a permutation with the smallest possible length that satisfies the requirement.
You need to solve this problem for different spaceships. For each spaceship , you are given an integer , which is the number of different ways to choose planets to accelerate the spaceship. Your task is to find an orbital speed sequence of sufficiently small length , such that there are exactly increasing subsequences that can be chosen from it.
Implementation Details
You need to implement the following function:
int[] construct_permutation(int64 k)
- is the required number of increasing subsequences.
- The function should return an array of elements, where each element is a number between and (inclusive).
- The returned array must be a valid permutation with exactly increasing subsequences.
- This function will be called a total of times. Each call is considered an independent scenario.
Input Format
The sample grader reads input in the following format:
- Line : .
- Line (): .
Output Format
For each , the sample grader prints one line containing the return value of the corresponding construct_permutation call. If an error occurs, it prints an error message.
2
3
8
2
1 0
3
0 1 2
Hint
Examples
Example
Consider the following call:
construct_permutation(3)
The function should return a permutation that has exactly increasing subsequences. One possible answer is , whose increasing subsequences are (the empty subsequence), , and .
Example
Consider the following call:
construct_permutation(8)
The function should return a permutation that has exactly increasing subsequences. One possible answer is .
Constraints
- .
- (for all ).
Subtasks
- ( points) (for all ). If all permutations you output have length at most and are correct, you will get points; otherwise, you will get points.
- ( points) No additional constraints. For this subtask, let be the maximum length among the permutations you output across all scenarios. Your score is computed according to the table below:
| Condition | Score |
|---|---|
Input Format
Output Format
Hint
Translated by ChatGPT 5