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

19150번 - Galois 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB69312643.333%

문제

Third time Evariste is attempting the entrance examination for the École Polytechnique. He managed to solve all the tasks very quickly, but the examiner accuses him of lack of explanations. He tries to make Evariste fail and gives him the following task: for the given permutation $p$ of size $N,ドル count the number of even permutations $q$ of size $N$ such that $p_{q_i} = q_{p_i}$ for all $i$ from 1ドル$ to $N$. As this number can be very large, the examiner wants to know it modulo 10ドル^9 + 7$.

A permutation is said to be even if it contains an even number of inversions. An inversion of a permutation $p$ is a pair of indices $(i, j)$ such that $i < j$ and $p_i > p_j$

Unfortunately for the examiner, who has no idea about the correct answer, Galois managed to solve the problem in only one second. You should help examiner and tell him the answer, or young Evariste will be denied again.

입력

The first line of the input contains a single integer $N,ドル which denotes the length of the permutation (1ドル \le N \le 500,000円$).

The second line describes the permutation $p$ itself and contains $N$ integers $p_i$ (1ドル \leq p_i \leq N,ドル $p_i \ne p_j$ for all $i \ne j$).

출력

Count the number of even permutations $q$ that satisfy the condition $p_{q_i} = q_{p_i},ドル and output it modulo 10ドル^9 + 7$.

제한

예제 입력 1

3
3 1 2

예제 출력 1

3

예제 입력 2

3
2 1 3

예제 출력 2

1

힌트

In the first example there are three appropriate permutations: (1, 2, 3), (2, 3, 1), (3, 1, 2). All of them are even.

In the second example there are two appropriate permutations: (1, 2, 3), (2, 1, 3). However, only first of these permutations is even.

출처

Camp > Petrozavodsk Programming Camp > Winter 2015 > Day 4: Moscow SU Tapirs Contest 2 G번

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

출처

대학교 대회

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

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