CF1863G.Swaps
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
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).
给你一个整数数组 a1,a2,…,an(其中 1≤ai≤n)。你可以执行以下操作若干次(可以为零次):
- 任选一个下标 i,并执行交换操作 swap(ai,aai)。
问:一共能到达多少种不同的数组?答案对 (109+7) 取模。
输入格式
The first line contains an integer n (1≤n≤106).
The second line contains n integers a1,a2,…,an (1≤ai≤n).
第一行包含一个整数 n(1≤n≤106)。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤n)。
输出格式
Output the number of attainable arrays modulo (109+7).
输出可达成数组的数量对 (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.
在第一个例子中,初始数组为 [1,1,2]。若对 i=3 执行操作,则交换 a3 与 a2,得到 [1,2,1]。可以证明不存在其他可达的数组。
在第二个例子中,四个可达的数组分别为 [2,1,4,3]、[1,2,4,3]、[1,2,3,4] 和 [2,1,3,4]。可以证明不存在其他可达的数组。
输入解题思路,AI测评打分。不知道怎么写?