#P11135. 【MX-X5-T7】「GFOI Round 1」Der Richter
【MX-X5-T7】「GFOI Round 1」Der Richter
Background
Original problem link: https://oier.team/problems/X5H。
Problem Description
First, we give some definitions for this problem.
A permutation of is called good if and only if $\exists k \in [1, n - 1], \max\limits_{i = 1}^k p_i = k$。
A sequence is called a swap plan of a permutation if and only if:
- , and is an integer;
- After performing, in order, the operation of swapping the numbers at positions and in for all , becomes good.
In particular, the sequence can be empty, meaning no swaps are performed.
A sequence is called a critical swap plan of a permutation if and only if:
- is a swap plan of ;
- Among all swap plans of , has the minimum length.
Let be the number of distinct critical swap plans of the permutation 。
A permutation is called a final state of another permutation if and only if:
- and have the same length;
- is good;
- There exists a critical swap plan of such that after performing, in order, the operation of swapping the numbers at positions and in for all , becomes identical to (i.e. )。
A permutation is called super good if and only if there exists exactly one permutation such that is a final state of 。
Given a prime and queries, each query gives two integers . You need to construct any super good permutation of length over such that , or report that there is no solution.
This problem will use a custom checker to verify whether your constructed permutation is correct, i.e. if a solution exists, outputting any permutation that satisfies the requirements will be accepted.
Input Format
The first line contains two positive integers , representing the number of queries and the modulus.
The next lines each contain two integers 。
Output Format
For each query:
- If there is no solution, output one line with a single integer ;
- Otherwise, output one line with integers, representing any valid permutation of 。
This problem will use a custom checker to verify whether your constructed permutation is correct, i.e. if a solution exists, outputting any permutation that satisfies the requirements will be accepted.
5 998244353
5 1
6 1
6 2
6 3
10 20
4 1 5 3 2
5 4 3 2 1 6
3 6 2 5 1 4
-1
5 10 4 3 2 9 8 7 1 6
Hint
Sample Explanation
For the first query, the permutation has only one critical swap plan , and since the only final state of is , is super good。
For the second query, the permutation has only one critical swap plan , and since the only final state of is , is super good。
For the third query, the permutation has two critical swap plans and , and since the only final state of is , is super good。
Constraints
This problem uses bundled testdata.
| Subtask ID | Special Property | Score | |
|---|---|---|---|
| None | |||
| A | |||
| B | |||
| None | |||
- Special property A: 。
- Special property B: 。
For all testdata, , , , , and is prime。
Translated by ChatGPT 5