CF1844H.Multiple of Three Cycles

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

An array a1,…,ana_1,\dots,a_n of length nn is initially all blank. There are nn updates where one entry of aa is updated to some number, such that aa becomes a permutation of 1,2,…,n1,2,\dots,n after all the updates.

After each update, find the number of ways (modulo 998 244 353998\,244\,353) to fill in the remaining blank entries of aa so that aa becomes a permutation of 1,2,…,n1,2,\dots,n and all cycle lengths in aa are multiples of 33.

A permutation of 1,2,…,n1,2,\dots,n is an array of length nn consisting of nn distinct integers from 11 to nn in arbitrary order. A cycle in a permutation aa is a sequence of pairwise distinct integers (i1,…,ik)(i_1,\dots,i_k) such that i2=ai1,i3=ai2,…,ik=aik−1,i1=aiki_2 = a_{i_1},i_3 = a_{i_2},\dots,i_k = a_{i_{k-1}},i_1 = a_{i_k}. The length of this cycle is the number kk, which is a multiple of 33 if and only if k≡0(mod3)k \equiv 0 \pmod 3.

一个长度为 nn 的数组 a1,…,ana_1,\dots,a_n 初始时所有元素均为空。接下来进行 nn 次更新,每次将数组 aa 中的一个空位置赋值为某个整数,使得所有更新完成后,aa 成为 1,2,…,n1,2,\dots,n 的一个排列。

每次更新后,请计算:将 aa 中剩余的空位置填满,使得最终 aa 成为 1,2,…,n1,2,\dots,n 的一个排列,且 aa 中所有循环的长度均为 33 的倍数的方案数(对 998 244 353998\,244\,353 取模)。

1,2,…,n1,2,\dots,n 的一个排列,是指由 11 到 nn 中互不相同的 nn 个整数按任意顺序组成的长度为 nn 的数组。在排列 aa 中,一个循环是指一组两两不同的整数序列 (i1,…,ik)(i_1,\dots,i_k),满足 i2=ai1, i3=ai2, …, ik=aik−1, i1=aiki_2 = a_{i_1},\,i_3 = a_{i_2},\,\dots,\,i_k = a_{i_{k-1}},\,i_1 = a_{i_k}。该循环的长度为 kk;当且仅当 k≡0(mod3)k \equiv 0 \pmod 3 时,该长度是 33 的倍数。

输入格式

The first line contains a single integer nn (3≤n≤3⋅1053 \le n \le 3 \cdot 10^5, n≡0(mod3)n \equiv 0 \pmod 3).

The ii-th of the next nn lines contains two integers xix_i and yiy_i, representing that the ii-th update changes axia_{x_i} to yiy_i.

It is guaranteed that x1,…,xnx_1,\dots,x_n and y1,…,yny_1,\dots,y_n are permutations of 1,2,…,n1,2,\dots,n, i.e. aa becomes a permutation of 1,2,…,n1,2,\dots,n after all the updates.

第一行包含一个整数 nn(3≤n≤3⋅1053 \le n \le 3 \cdot 10^5,且 n≡0(mod3)n \equiv 0 \pmod 3)。

接下来的 nn 行中,第 ii 行包含两个整数 xix_i 和 yiy_i,表示第 ii 次更新将 axia_{x_i} 修改为 yiy_i。

保证 x1,…,xnx_1,\dots,x_n 和 y1,…,yny_1,\dots,y_n 均为 1,2,…,n1,2,\dots,n 的排列,即所有更新完成后,数组 aa 成为 1,2,…,n1,2,\dots,n 的一个排列。

输出格式

Output nn lines: the number of ways (modulo 998 244 353998\,244\,353) after the first 1,2,…,n1,2,\dots,n updates.

输出 nn 行:分别表示执行前 1,2,…,n1,2,\dots,n 次更新后,方案数对 998 244 353998\,244\,353 取模的结果。

输入输出样例

  • 输入#1

    6
    3 2
    1 4
    4 5
    2 6
    5 1
    6 3

    输出#1

    32
    8
    3
    2
    1
    1
  • 输入#2

    3
    1 1
    2 3
    3 2

    输出#2

    0
    0
    0
  • 输入#3

    18
    1 2
    2 3
    3 4
    4 5
    5 6
    6 7
    7 8
    8 9
    9 10
    10 11
    11 12
    12 13
    13 14
    14 15
    15 16
    16 17
    17 18
    18 1

    输出#3

    671571067
    353924552
    521242461
    678960117
    896896000
    68992000
    6272000
    627200
    62720
    7840
    1120
    160
    32
    8
    2
    1
    1
    1

说明/提示

In the first sample, for example, after the 33rd update the 33 ways to complete the permutation a=[4,_,2,5,_,_]a = [4,\_,2,5,\_,\_] are as follows:

  • [4,1,2,5,6,3][4,1,2,5,6,3]: The only cycle is (1 4 5 6 3 2)(1\,4\,5\,6\,3\,2), with length 66.
  • [4,6,2,5,1,3][4,6,2,5,1,3]: The cycles are (1 4 5)(1\,4\,5) and (2 6 3)(2\,6\,3), with lengths 33 and 33.
  • [4,6,2,5,3,1][4,6,2,5,3,1]: The only cycle is (1 4 5 3 2 6)(1\,4\,5\,3\,2\,6), with length 66.

In the second sample, the first update creates a cycle of length 11, so there are no ways to make all cycle lengths a multiple of 33.

在第一个样例中,例如,在第 33 次更新后,完成排列 a=[4,_,2,5,_,_]a = [4,\_,2,5,\_,\_] 的 33 种方式如下:

  • [4,1,2,5,6,3][4,1,2,5,6,3]:唯一的循环是 (1 4 5 6 3 2)(1\,4\,5\,6\,3\,2),长度为 66。
  • [4,6,2,5,1,3][4,6,2,5,1,3]:循环为 (1 4 5)(1\,4\,5) 和 (2 6 3)(2\,6\,3),长度分别为 33 和 33。
  • [4,6,2,5,3,1][4,6,2,5,3,1]:唯一的循环是 (1 4 5 3 2 6)(1\,4\,5\,3\,2\,6),长度为 66。

在第二个样例中,第一次更新产生了一个长度为 11 的循环,因此不存在使所有循环长度均为 33 的倍数的方案。

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

首页