AT_arc228_a.Row and Col swap

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given permutations P=(P1,P2,…,PN)P=(P_1,P_2,\dots,P_N) and Q=(Q1,Q2,…,QN)Q=(Q_1,Q_2,\dots,Q_N) of (1,2,…,N)(1,2,\dots,N).

For PP and QQ, you repeat the following MM times: choose and perform one of the operations below.

  • Choose integers ii and jj satisfying 1≤i<j≤N1 \le i < j \le N, and swap PiP_i and PjP_j.
  • Choose integers ii and jj satisfying 1≤i<j≤N1 \le i < j \le N, and swap QiQ_i and QjQ_j.
  • Choose an integer ii satisfying 1≤i≤N1 \le i \le N, and swap PiP_i and QiQ_i.

Find the number, modulo 998244353998244353, of sequences of operations such that both PP and QQ are permutations of (1,2,…,N)(1,2,\dots,N) after the MM operations.

给你两个 (1,2,…,N)(1,2,\dots,N) 的排列 P=(P1,P2,…,PN)P=(P_1,P_2,\dots,P_N) 和 Q=(Q1,Q2,…,QN)Q=(Q_1,Q_2,\dots,Q_N)。

对 PP 和 QQ,重复执行以下操作共 MM 次:

  • 选择满足 1≤i<j≤N1 \le i < j \le N 的整数 ii 和 jj,交换 PiP_i 与 PjP_j;
  • 选择满足 1≤i<j≤N1 \le i < j \le N 的整数 ii 和 jj,交换 QiQ_i 与 QjQ_j;
  • 选择满足 1≤i≤N1 \le i \le N 的整数 ii,交换 PiP_i 与 QiQ_i。

求满足“经过 MM 次操作后,PP 和 QQ 均仍为 (1,2,…,N)(1,2,\dots,N) 的排列”的操作序列的个数,答案对 998244353998244353 取模。

输入格式

The input is given from Standard Input in the following format:

NN MM
P1 P2 … PNP_1\ P_2\ \dots\ P_N
Q1 Q2 … QNQ_1\ Q_2\ \dots\ Q_N

输入从标准输入中按以下格式给出:

NN MM
P1 P2 … PNP_1\ P_2\ \dots\ P_N
Q1 Q2 … QNQ_1\ Q_2\ \dots\ Q_N

输出格式

Output the answer.

输出答案。

输入输出样例

  • 输入#1

    3 1
    1 2 3
    1 3 2

    输出#1

    7
  • 输入#2

    3 2
    1 2 3
    1 3 2

    输出#2

    53
  • 输入#3

    8 15
    6 4 8 3 2 7 1 5
    1 6 4 5 7 2 8 3

    输出#3

    571380540

说明/提示

Sample 1 Explanation:
For example, the following sequence of operations satisfies the condition.

  • Choose i=1i = 1 in an operation of the third kind to swap P1P_1 and Q1Q_1. Now P=(1,2,3)P=(1,2,3) and Q=(1,3,2)Q=(1,3,2).

Any sequence of operations composed of exactly one of the following seven operations satisfies the condition: the three operations that swap two elements of PP, the three operations that swap two elements of QQ, and the operation described above that swaps P1P_1 and Q1Q_1.

Constraints

  • 1≤N,M≤5001 \le N,M \le 500
  • PP and QQ are permutations of (1,2,…,N)(1,2,\dots,N).
  • All input values are integers.

样例 1 解释:
例如,以下操作序列满足条件。

  • 在第三类操作中选择 i=1i = 1,交换 P1P_1 和 Q1Q_1。此时 P=(1,2,3)P=(1,2,3),Q=(1,3,2)Q=(1,3,2)。

任何恰好由以下七种操作之一构成的操作序列均满足条件:三类交换 PP 中两个元素的操作、三类交换 QQ 中两个元素的操作,以及上述交换 P1P_1 和 Q1Q_1 的操作。

限制条件

  • 1≤N,M≤5001 \le N,M \le 500
  • PP 和 QQ 均为 (1,2,…,N)(1,2,\dots,N) 的排列。
  • 所有输入值均为整数。

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

首页