Logo
(追記) (追記ここまで)

19190번 - Bermutation 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 256 MB5000.000%

문제

Your are given a permutation $p$ of integers from 1ドル$ to $n$. You are allowed to modify this permutation in the following way: choose a segment of 2ドル b$ consecutive elements and swap the halves of this segment. Formally, if you choose the segment $a_{i}, a_{i + 1} \ldots, a_{i + 2 b - 1},ドル you will get $a_{i + b}, a_{i + b + 1}, \ldots, a_{i + 2 b - 1}, a_{i}, a_{i + 1}, \ldots, a_{i + b - 1}$ after swapping its halves.

Consider the set $S$ of all permutations which can be obtained from the given permutation $p$ by applying this modification zero or more times. The segment of 2ドル b$ consecutive elements for each modification can be chosen independently of the segments chosen for other modifications. List all these permutations in lexicographical order and enumerate them starting from 1ドル$. Your task is to find the number of $p$ itself in this ordered list. Print the answer modulo 120ドル,586円,241円$.

입력

The first line of input contains one positive integer $T,ドル the number of test cases. The test cases follow.

Each test case is given on two lines. The first line contains with two integers $n$ and $b$ (2ドル \le n \le 10^5,ドル 1ドル \le b$ and 2ドル b \le n$). The second line of each test case contains $n$ integers: the permutation $p$. Each integer from 1ドル$ to $n$ appears on this line exactly once.

The sum of all $n$ in the input does not exceed 10ドル^5$.

출력

Print the 1ドル$-based number of permutation $p$ in the lexicographically ordered list of all permutations which can be obtained by the described modifications, modulo 120ドル,586円,241円$.

제한

예제 입력 1

2
5 1
2 3 1 4 5
5 2
2 3 1 4 5

예제 출력 1

31
3

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2015 > Day 7: Karelia Cup Day 1, Grand Prix of Karelia A번

Contest > Open Cup > 2014/2015 Season > Stage 8: Grand Prix of Karelia A번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /