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

8364번 - Idempotent Functions 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB63363260.377%

문제

You are given a positive integer n. By A we mean the set {1, 2, 3, ..., n}. Function f : AA is called a permutation if it is injective (for distinct arguments returns distinct values). Function f : AA is called idempotent if for every iA holds f(f(i)) = f(i).

You are given a function f : AA. How many pairs of functions (g, h) satisfy following conditions:

  • g : AA is a permutation,
  • h : AA is idempotent,
  • for every iA holds f(i) = h(g(i))?

Write a program which:

  • reads number n and description of function f from the standard input ,
  • determines the number of pairs of functions (g, h) satisfying the requirement described above,
  • writes the result to the standard output.

입력

In the first line of input there is one integer n (1 ≤ n ≤ 200 000). Second line contains a description of function f : f(i) (1 ≤ f(i) ≤ n) for i = 1, ..., n, separated with single spaces.

출력

In the first line of output there should be a single integer: the remainder of the division by 1 000 000 007 of the number of different pairs of functions (g, h) satisfying the requirement.

제한

예제 입력 1

8
7 4 5 1 7 4 4 1

예제 출력 1

288

힌트

출처

Contest > Algorithmic Engagements > PA 2008 7-2번

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

출처

대학교 대회

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

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