QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#15396. Divisor Card Game

الإحصائيات

在台湾,许多数学老师设计了棋盘和卡牌游戏,以帮助学生掌握困难的数学概念。最近,一种特定的卡牌游戏在中小学教师中流行起来,因为它能有效地帮助学生理解约数和倍数的概念,同时对师生双方都极具吸引力。

游戏规则如下。老师准备了 $n$ 张不同的卡牌,编号从 1 到 $n$。第 $i$ 张卡牌上写有一个整数 $a_i$,且整数 $a_1, a_2, \dots, a_n$ 严格递增。

共有 $m$ 名编号为 1 到 $m$ 的学生参与游戏。游戏开始前,每名学生会收到 $n$ 张卡牌中的一个非空子集。没有任何两名学生拥有相同的卡牌,且至少有一张卡牌未被分发。

设 $k$ 为初始时未分发卡牌的数量。游戏共进行 $k$ 轮。每一轮按顺序执行以下步骤:

  1. 老师从剩余的未分发卡牌中随机均匀地选择一张并向所有学生展示。设这张卡牌上的整数为 $c$。
  2. 每名学生同时从自己持有的卡牌中恰好选择一张。
  3. 展示卡牌的归属判定如下:
    • 在所有学生选择的卡牌数值中,考虑那些能被 $c$ 整除的数值。
    • 如果存在一个或多个这样的数值,选择能被 $c$ 整除的数值中最小值的学生赢得该展示卡牌,并将其加入自己的卡牌集合中。
    • 如果没有学生选择的卡牌数值能被 $c$ 整除,则该展示卡牌被丢弃(保持无人拥有)。被丢弃的卡牌不会在后续轮次中使用。

每名学生在整个游戏过程中遵循相同的策略:

  • 如果学生拥有的卡牌中至少有一张数值能被 $c$ 整除,他们会选择其中数值最小的一张。
  • 否则,他们会选择自己拥有的卡牌中数值最小的一张。

假设所有学生在每一轮都遵循此策略,请确定游戏结束时每名学生预期拥有的卡牌数量。

输入格式

第一行包含两个整数 $n$ 和 $m$,分别表示卡牌数量和学生人数。

第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$,其中 $a_i$ 是第 $i$ 张卡牌上的整数。

第三行包含 $n$ 个整数 $b_1, b_2, \dots, b_n$,其中 $b_i$ 描述了游戏开始前第 $i$ 张卡牌的归属:若 $b_i \neq 0$,则该卡牌由第 $b_i$ 名学生拥有;若 $b_i = 0$,则该卡牌未被分发。

  • $1 \le m < n \le 600$
  • $1 \le a_i \le 10^{18}$
  • $0 \le b_i \le m$
  • 对于所有 $1 \le i < n$,满足 $a_i < a_{i+1}$。
  • 对于 $j = 0, 1, \dots, m$,至少存在一个 $i$ 使得 $b_i = j$。

输出格式

在一行中输出 $m$ 个数字,其中第 $i$ 个数字表示第 $i$ 名学生在游戏结束时预期拥有的卡牌数量。

可以证明每个答案都可以表示为有理数 $\frac{p}{q}$,其中 $q$ 不是 998244353 的倍数。因此,请输出每个数字 $p \times q^{-1} \pmod{998244353}$,其中 $q^{-1}$ 表示 $q$ 在模 998244353 下的乘法逆元。

样例

样例输入 1

5 2
1 2 3 4 5
0 0 1 2 1

样例输出 1

499122179 499122179

样例输入 2

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

样例输出 2

831870297 166374061

样例输入 3

8 3
4 5 8 9 12 18 20 24
0 0 0 0 0 2 1 3

样例输出 3

332748120 2 665496239

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.