CF1863G.Swaps

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an array of integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤n1 \le a_i \le n). You can perform the following operation several (possibly, zero) times:

  • pick an arbitrary ii and perform swap(ai,aai)(a_i, a_{a_i}).

How many distinct arrays is it possible to attain? Output the answer modulo (109+7)(10^9 + 7).

给你一个整数数组 a1,a2,…,ana_1, a_2, \dots, a_n(其中 1≤ai≤n1 \le a_i \le n)。你可以执行以下操作若干次(可以为零次):

  • 任选一个下标 ii,并执行交换操作 swap(ai,aai)\text{swap}(a_i, a_{a_i})。

问:一共能到达多少种不同的数组?答案对 (109+7)(10^9 + 7) 取模。

输入格式

The first line contains an integer nn (1≤n≤1061 \le n \le 10^6).

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤n1\le a_i\le n).

第一行包含一个整数 nn(1≤n≤1061 \le n \le 10^6)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤n1\le a_i\le n)。

输出格式

Output the number of attainable arrays modulo (109+7)(10^9 + 7).

输出可达成数组的数量对 (109+7)(10^9 + 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][1, 1, 2]. If we perform the operation with i=3i = 3, we swap a3a_3 and a2a_2, obtaining [1,2,1][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][2, 1, 4, 3], [1,2,4,3][1, 2, 4, 3], [1,2,3,4][1, 2, 3, 4], [2,1,3,4][2, 1, 3, 4]. One can show that there are no other attainable arrays.

在第一个例子中,初始数组为 [1,1,2][1, 1, 2]。若对 i=3i = 3 执行操作,则交换 a3a_3 与 a2a_2,得到 [1,2,1][1, 2, 1]。可以证明不存在其他可达的数组。

在第二个例子中,四个可达的数组分别为 [2,1,4,3][2, 1, 4, 3]、[1,2,4,3][1, 2, 4, 3]、[1,2,3,4][1, 2, 3, 4] 和 [2,1,3,4][2, 1, 3, 4]。可以证明不存在其他可达的数组。

输入解题思路,AI测评打分。不知道怎么写?

首页