AT_abc462_g.Completely Wrong

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

There is a box containing NN balls numbered 11 through NN. Each ball is painted with a color represented as an integer, and ball ii is painted with color CiC_i.

Takahashi performed NN operations. The kk-th operation (1≤k≤N)(1\le k\le N) is as follows:

  • Draw one ball uniformly at random from the box and discard it. If the drawn ball has color GkG_k, gain 11 point.

Find the probability, modulo 998244353998244353, that the total score over NN operations is 00 points.

Definition of probability modulo 998244353998244353

It can be proved that the sought probability is always a rational number. Furthermore, under the constraints of this problem, when the rational number is expressed as an irreducible fraction PQ\frac{P}{Q}, it can be proved that Q≢0(mod998244353)Q {{}\not\equiv{}} 0 \pmod{998244353}. Thus, there exists a unique integer RR satisfying R×Q≡P(mod998244353)R \times Q \equiv P \pmod{998244353} and 0≤R<9982443530 \leq R \lt 998244353. Find this RR.

盒中有 NN 个编号为 11 至 NN 的球。每个球被涂上一种颜色,颜色用整数表示;其中第 ii 个球的颜色为 CiC_i。

高桥进行了 NN 次操作。第 kk 次操作(1≤k≤N1 \le k \le N)如下:

  • 从盒中均匀随机抽取一个球并丢弃它。若抽到的球颜色为 GkG_k,则获得 11 分。

求在全部 NN 次操作中总得分为 00 分的概率(对 998244353998244353 取模)。

概率对 998244353998244353 取模的定义

可以证明:所求概率恒为有理数。此外,在本题约束下,当该有理数表示为既约分数 PQ\frac{P}{Q} 时,可证 Q≢0(mod998244353)Q {{}\not\equiv{}} 0 \pmod{998244353}。因此,存在唯一整数 RR 满足 R×Q≡P(mod998244353)R \times Q \equiv P \pmod{998244353} 且 0≤R<9982443530 \leq R \lt 998244353。请输出该 RR。

输入格式

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

NN
C1C_1 C2C_2 …\ldots CNC_N
G1G_1 G2G_2 …\ldots GNG_N

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

NN
C1C_1 C2C_2 …\ldots CNC_N
G1G_1 G2G_2 …\ldots GNG_N

输出格式

Output the sought probability modulo 998244353998244353.

输出所求概率对 998244353998244353 取模的结果。

输入输出样例

  • 输入#1

    3
    1 2 3
    1 1 2

    输出#1

    332748118
  • 输入#2

    3
    1 1 3
    3 3 3

    输出#2

    0
  • 输入#3

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

    输出#3

    316110712

说明/提示

Sample 1 Explanation:
For example, the operations may proceed as follows:

  • First operation: A ball with color 22 is drawn from the box.
  • Second operation: A ball with color 11 is drawn from the box. Gain 11 point.
  • Third operation: A ball with color 33 is drawn from the box.

In this case, the total score is 11 point.

The probability that Takahashi's total score is 00 is 13\displaystyle \frac13.

Sample 2 Explanation:
Takahashi's total score is always 11 point.

Constraints

  • 1≤N≤2×1051\le N\le 2\times 10^5
  • 1≤Ci,Gk≤N1\le C_i,G_k\le N
  • All input values are integers.

样例 1 解释:
例如,操作过程可能如下所示:

  • 第一次操作:从盒子中抽出一个颜色为 22 的球。
  • 第二次操作:从盒子中抽出一个颜色为 11 的球,获得 11 分。
  • 第三次操作:从盒子中抽出一个颜色为 33 的球。

此时,总得分为 11 分。

高桥的总得分等于 00 的概率为 13\displaystyle \frac{1}{3}。

样例 2 解释:
高桥的总得分恒为 11 分。

限制条件

  • 1≤N≤2×1051\le N\le 2\times 10^5
  • 1≤Ci,Gk≤N1\le C_i,G_k\le N
  • 所有输入值均为整数。

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

首页