luogu#P16608. [SYSUCPC 2025] Larger or Smaller

    ID: 16701 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP2025组合数学高校校赛

[SYSUCPC 2025] Larger or Smaller

Problem Description

In his recent work on permutation properties, Dr.Z\texttt{Dr.Z} investigates the relationship between element values and their indices. A key focus is the cardinality of the set of indices ii where pi>ip_i>i (called larger position\bf{larger\ position}) and where pi<ip_i<i (called smaller position\bf{smaller\ position}). To formalize this, he defines f(n,x,y)f(n,x,y) as the number of permutations of nn elements containing exactly xx larger positions and yy smaller positions. Dr.Z\texttt{Dr.Z} now aims to characterize this function completely by determining the values of f(n,x,y)f(n,x,y) across all valid positive integers xx and yy after modulo mm. Could you help him solve this problem efficiently?

Input Format

The only line contains two integers n,m(2n2000,2m109+7)n,m(2\le n\le 2000,2\le m\le 10^9+7).

Output Format

There are n1n-1 rows in total. The ii-th row contains nin-i integers. The jj-th integer represents the result of f(n,i,j)f(n,i,j) modulo mm.

5 998244353
10 10 5 1
10 35 21
5 21
1

Hint

The five permutations of x=1,y=3x=1,y=3 are [1,5,2,3,4],[4,1,2,3,5],[5,1,2,4,3],[5,1,3,2,4][1,5,2,3,4], [4,1,2,3,5], [5,1,2,4,3], [5,1,3,2,4], and [5,2,1,3,4][5,2,1,3,4].