#P11135. 【MX-X5-T7】「GFOI Round 1」Der Richter

    ID: 11534 远端评测题 4000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>搜索Special JudgeO2优化剪枝状压 DP梦熊比赛

【MX-X5-T7】「GFOI Round 1」Der Richter

Background

Original problem link: https://oier.team/problems/X5H


Der Richter - Ωμεγα

Problem Description

First, we give some definitions for this problem.

A permutation p1,p2,,pnp_1, p_2, \ldots, p_n of 1n1 \sim n is called good if and only if $\exists k \in [1, n - 1], \max\limits_{i = 1}^k p_i = k$。

A sequence x1,x2,,xkx_1, x_2, \ldots, x_k is called a swap plan of a permutation p1,p2,,pnp_1, p_2, \ldots, p_n if and only if:

  • 1ik\forall 1 \le i \le k, 1xin11 \le x_i \le n - 1 and xix_i is an integer;
  • After performing, in order, the operation of swapping the numbers at positions xix_i and xi+1x_i + 1 in pp for all i=1ki = 1 \sim k, pp becomes good.

In particular, the sequence xx can be empty, meaning no swaps are performed.

A sequence x1,x2,,xkx_1, x_2, \ldots, x_k is called a critical swap plan of a permutation p1,p2,,pnp_1, p_2, \ldots, p_n if and only if:

  • xx is a swap plan of pp
  • Among all swap plans of pp, xx has the minimum length.

Let f(p)f(p) be the number of distinct critical swap plans of the permutation pp

A permutation qq is called a final state of another permutation pp if and only if:

  • pp and qq have the same length;
  • qq is good
  • There exists a critical swap plan x1,x2,,xkx_1, x_2, \ldots, x_k of pp such that after performing, in order, the operation of swapping the numbers at positions xix_i and xi+1x_i + 1 in pp for all i=1ki = 1 \sim k, pp becomes identical to qq (i.e. 1ip,pi=qi\forall 1 \le i \le |p|, p_i = q_i)。

A permutation pp is called super good if and only if there exists exactly one permutation qq such that qq is a final state of pp

Given a prime PP and qq queries, each query gives two integers n,mn, m. You need to construct any super good permutation pp of length nn over 1n1 \sim n such that f(p)m(modP)f(p) \equiv m \pmod P, 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 q,Pq, P, representing the number of queries and the modulus.

The next qq lines each contain two integers n,mn, m

Output Format

For each query:

  • If there is no solution, output one line with a single integer 1-1
  • Otherwise, output one line with nn integers, representing any valid permutation p1,p2,,pnp_1, p_2, \ldots, p_n of 1n1 \sim n

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 p=[4,1,5,3,2]p = [4, 1, 5, 3, 2] has only one critical swap plan x=[1]x = [1], and since the only final state of pp is q=[1,4,5,3,2]q = [1, 4, 5, 3, 2], pp is super good

For the second query, the permutation p=[5,4,3,2,1,6]p = [5, 4, 3, 2, 1, 6] has only one critical swap plan x=[]x = [], and since the only final state of pp is q=[5,4,3,2,1,6]q = [5, 4, 3, 2, 1, 6], pp is super good

For the third query, the permutation p=[3,6,2,5,1,4]p = [3, 6, 2, 5, 1, 4] has two critical swap plans x=[2,4,3]x = [2, 4, 3] and x=[4,2,3]x = [4, 2, 3], and since the only final state of pp is q=[3,2,1,6,5,4]q = [3, 2, 1, 6, 5, 4], pp is super good

Constraints

This problem uses bundled testdata.

Subtask ID nn \le Special Property Score
11 88 None 1717
22 5050 A 33
33 B
44 1818 None 1919
55 4040 1616
66 5050 99
77 6060 1010
88 7070 1111
99 8080 1212
  • Special property A: m=0m = 0
  • Special property B: m=1m = 1

For all testdata, 1q1041 \le q \le 10^4, 9×108<P<1099 \times 10^8 < P < 10^9, 2n802 \le n \le 80, 0m<P0 \le m < P, and PP is prime

Translated by ChatGPT 5