CF2172D.Divisor Card Game

NOI/NOI+/CTSC

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

In Taiwan, many mathematics teachers design board and card games to help students grasp difficult mathematical concepts. Recently, a particular card game has gone viral among elementary and middle school teachers because it effectively helps students understand the concepts of divisors and multiples, while also being highly engaging for both teachers and students.

The rules of the game are as follows. The teacher prepares nn distinct cards, labeled from 11 to nn. The ii-th card has an integer value aia_i written on it, and the integers a1,a2,…,ana_1, a_2, \dots, a_n are in a strictly increasing order.

There are mm students labeled from 11 to mm participating in the game. Before the game begins, each student receives a nonempty subset of the nn cards. No two students share any card, and at least one card remains undealt.

Let kk denote the number of undealt cards initially. The game consists of kk rounds. In each round, the following steps occur in order:

  1. The teacher selects one of the remaining undealt cards uniformly at random and reveals it to all students. Let cc be the integer written on this card.
  2. Each student simultaneously chooses exactly one card from their own collection.
  3. The ownership of the revealed card is determined as follows:
    • Among the values of all cards chosen by the students, consider those that are divisible by cc.
    • If there are one or more such values, the student who selected a card with the smallest divisible value wins the revealed card and adds it to their collection.
    • If no chosen cards have value divisible by cc, the revealed card is discarded (remains unowned). Discarded cards are not used in subsequent rounds.

Each student follows the same strategy throughout the game:

  • If the student owns at least one card whose value is divisible by cc, they choose the card with the smallest value.
  • Otherwise, they choose the card with the smallest value among those they own.

Assuming that all students follow this strategy in every round, determine the expected number of cards that each student will own at the end of the game.

在台湾,许多数学教师设计棋盘游戏和纸牌游戏,以帮助学生掌握较难的数学概念。最近,一款特定的纸牌游戏在小学和初中教师中迅速走红,因为它能有效帮助学生理解“因数”与“倍数”的概念,同时对师生双方都极具吸引力。

游戏规则如下:教师准备 nn 张互不相同的卡片,编号为 11 至 nn。第 ii 张卡片上写有一个整数值 aia_i,且整数序列 a1,a2,…,ana_1, a_2, \dots, a_n 严格递增。

共有 mm 名学生参与游戏,编号为 11 至 mm。游戏开始前,每名学生分得 nn 张卡片的一个非空子集;任意两名学生所持卡片互不重叠,且至少有一张卡片未被分发。

设初始未分发卡片的数量为 kk。整个游戏共进行 kk 轮。每轮按以下顺序执行:

  1. 教师从当前剩余的未分发卡片中等概率随机选取一张,并向所有学生展示。设该卡片上的整数为 cc。
  2. 每名学生同时从自己持有的卡片中恰好选择一张。
  3. 所展示卡片的归属按如下规则确定:
    • 考察所有学生所选卡片的数值中,能被 cc 整除的那些值;
    • 若存在至少一个这样的值,则所选数值最小的该类学生赢得这张展示卡片,并将其加入自己的卡片集合;
    • 若没有任何学生所选卡片的数值能被 cc 整除,则该展示卡片被弃置(无人获得);弃置卡片不再参与后续轮次。

每名学生在整个游戏中均采用完全相同的策略:

  • 若该学生手中至少拥有一张数值能被 cc 整除的卡片,则他/她选择其中数值最小的一张;
  • 否则,他/她选择自己手中数值最小的一张卡片。

假设所有学生在每一轮中均严格遵循上述策略,求游戏结束时,每名学生最终所持卡片数量的期望值。

输入格式

The first line contains two integers nn and mm, representing the number of cards and the number of students, respectively.

The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n, where aia_i is the integer on the ii-th card.

The third line contains nn integers b1,b2,…,bnb_1,b_2,\ldots,b_n, where bib_i describes the ownership of the ii-th card before the game begins: it is owned by the bib_i-th student if bi≠0b_i \ne 0, and is undealt otherwise.

  • 1≤m<n≤6001 \leq m \lt n \leq 600
  • 1≤ai≤10181 \le a_i \le 10^{18}
  • 0≤bi≤m0 \leq b_i \leq m
  • ai<ai+1a_i \lt a_{i + 1} for all 1≤i<n1 \le i \lt n.
  • There is at least one ii such that bi=jb_i = j for j=0,1,…,mj = 0,1,\ldots,m.

第一行包含两个整数 nn 和 mm,分别表示卡片的数量和学生的数量。

第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n,其中 aia_i 表示第 ii 张卡片上的整数。

第三行包含 nn 个整数 b1,b2,…,bnb_1,b_2,\ldots,b_n,其中 bib_i 描述了游戏开始前第 ii 张卡片的归属情况:若 bi≠0b_i \ne 0,则该卡片属于第 bib_i 号学生;否则(即 bi=0b_i = 0)该卡片尚未分发。

  • 1≤m<n≤6001 \leq m \lt n \leq 600
  • 1≤ai≤10181 \le a_i \le 10^{18}
  • 0≤bi≤m0 \leq b_i \leq m
  • 对所有 1≤i<n1 \le i \lt n,有 ai<ai+1a_i \lt a_{i + 1}。
  • 对每个 j=0,1,…,mj = 0,1,\ldots,m,至少存在一个 ii 使得 bi=jb_i = j。

输出格式

Print mm numbers in a new line, where the ii-th number represents the expected number of cards the ii-th student will own at the end of the game.

It can be proven that each answer can be represented by a rational number pq\frac{p}{q} where qq is not a multiple of 998244353998244353. Therefore, you are asked to print p×q−1p \times q^{-1} modulo 998244353998244353 for each number, where q−1q^{-1} means the multiplicative inverse of qq modulo 998244353998244353.

在新行中输出 mm 个数,其中第 ii 个数表示游戏结束时第 ii 位学生所拥有的卡片数量的期望值。

可以证明,每个答案均可表示为有理数 pq\frac{p}{q},且 qq 不是 998244353998244353 的倍数。因此,对于每个数,你需要输出 p×q−1 mod 998244353p \times q^{-1} \bmod 998244353,其中 q−1q^{-1} 表示 qq 在模 998244353998244353 意义下的乘法逆元。

输入输出样例

  • 输入#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

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

首页