logo AlgoBeat OnlineJudge
登录 注册

#215797. [JAG 2024 Summer Camp #2] Linear Time Inversion Number

内存限制:1024 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Given a permutation of length , Alice uses the inversion number as a measure of how close is to the permutation , while Bob uses the metric .

Here, the inversion number is the number of pairs such that and .

Given a sequence of length , there are permutations of length that have as their prefix.

Find the number of these permutations for which Alice's metric and Bob's metric are equal, and return the result modulo .

输入格式

The input is given in the following format:

  • All input values are integers.

输出格式

Output the answer.

样例

样例输入 1

5 3
2 3 5

样例输出 1

1

样例输入 2

10 10
3 1 4 5 9 2 6 8 7 10

样例输出 2

0

样例输入 3

6 0

样例输出 3

132