CodeQUEEN 2026 予選 (AtCoder Beginner Contest 462)
G
完全错误
Completely Wrong
AtCoder
⌀ 2232
原题
← F→

完全错误AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

There is a box containing $N$ balls numbered $1$ through $N$. Each ball is painted with a color represented as an integer, and ball $i$ is painted with color $C_i$.

有一个盒子,里面有 $N$ 个编号为 $1$ 至 $N$ 的球。每个球都涂有一种用整数表示的颜色,球 $i$ 的颜色为 $C_i$。AI (CI翻译)

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

高桥进行了 $N$ 次操作。第 $k$ 次操作 $(1\le k\le N)$ 如下:AI (CI翻译)

  • Draw one ball uniformly at random from the box and discard it. If the drawn ball has color $G_k$, gain $1$ point.
  • 从盒子中等概率随机取出一个球并丢弃。如果取出的球颜色为 $G_k$,则获得 $1$ 分。
AI (CI翻译)

Find the probability, modulo $998244353$, that the total score over $N$ operations is $0$ points.

求经过 $N$ 次操作后总得分为 $0$ 分的概率,模 $998244353$。AI (CI翻译)

Definition of probability modulo $998244353$ 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 $\frac{P}{Q}$, it can be proved that $Q {{}\not\equiv{}} 0 \pmod{998244353}$. Thus, there exists a unique integer $R$ satisfying $R \times Q \equiv P \pmod{998244353}$ and $0 \leq R \lt 998244353$. Find this $R$.

概率模 $998244353$ 的定义:可以证明,所求概率总是有理数。此外,在本题的约束条件下,将该有理数表示为最简分数 $\frac{P}{Q}$ 时,可以证明 $Q {{}\not\equiv{}} 0 \pmod{998244353}$。因此,存在唯一的整数 $R$ 满足 $R \times Q \equiv P \pmod{998244353}$ 且 $0 \leq R \lt 998244353$。求出这个 $R$。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1\le N\le 2\times 10^5$
  • $1\le C_i,G_k\le N$
  • All input values are integers.
  • $1\le N\le 2\times 10^5$
  • $1\le C_i,G_k\le N$
  • 所有输入值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

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

输入从标准输入按以下格式给出:AI (CI翻译)

N
C_1 C_2 \ldots C_N
G_1 G_2 \ldots G_N

N
C_1 C_2 \ldots C_N
G_1 G_2 \ldots G_N
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output the sought probability modulo $998244353$.

输出所求概率模 $998244353$ 的结果。AI (CI翻译)

样例

Input #1
3
1 2 3
1 1 2
Output #1
332748118
For example, the operations may proceed as follows: - First operation: A ball with color $2$ is drawn from the box. - Second operation: A ball with color $1$ is drawn from the box. Gain $1$ point. - Third operation: A ball with color $3$ is drawn from the box. In this case, the total score is $1$ point. The probability that Takahashi's total score is $0$ is $\displaystyle \frac13$.
Input #2
3
1 1 3
3 3 3
Output #2
0
Takahashi's total score is always $1$ point.
Input #3
6
1 2 3 3 4 5
3 5 3 5 5 4
Output #3
316110712
题目信息
题号
abc462_g
时间限制
3 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。