CF1863G.Swaps
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array of integers a1,a2,…,an ( 1≤ai≤n ). You can perform the following operation several (possibly, zero) times:
- pick an arbitrary i and perform swap (ai,aai) .
How many distinct arrays is it possible to attain? Output the answer modulo (109+7) .
输入格式
The first line contains an integer n ( 1≤n≤106 ).
The second line contains n integers a1,a2,…,an ( 1≤ai≤n ).
输出格式
Output the number of attainable arrays modulo (109+7) .
输入输出样例
输入#1
3 1 1 2
输出#1
2
输入#2
4 2 1 4 3
输出#2
4
输入#3
6 2 3 1 1 1 2
输出#3
18
说明/提示
In the first example, the initial array is [1,1,2] . If we perform the operation with i=3 , we swap a3 and a2 , obtaining [1,2,1] . One can show that there are no other attainable arrays.
In the second example, the four attainable arrays are [2,1,4,3] , [1,2,4,3] , [1,2,3,4] , [2,1,3,4] . One can show that there are no other attainable arrays.