CF1017H.The Films

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

In "The Man in the High Castle" world, there are mm different film endings.

Abendsen owns a storage and a shelf. At first, he has nn ordered films on the shelf. In the ii-th month he will do:

  1. Empty the storage.
  2. Put ki⋅mk_i \cdot m films into the storage, kik_i films for each ending.
  3. He will think about a question: if he puts all the films from the shelf into the storage, then randomly picks nn films (from all the films in the storage) and rearranges them on the shelf, what is the probability that sequence of endings in [li,ri][l_i, r_i] on the shelf will not be changed? Notice, he just thinks about this question, so the shelf will not actually be changed.

Answer all Abendsen's questions.

Let the probability be fraction PiP_i. Let's say that the total number of ways to take nn films from the storage for ii-th month is AiA_i, so Pi⋅AiP_i \cdot A_i is always an integer. Print for each month Pi⋅Ai(mod998244353)P_i \cdot A_i \pmod {998244353}.

998244353998244353 is a prime number and it is equal to 119⋅223+1119 \cdot 2^{23} + 1.

It is guaranteed that there will be only no more than 100100 different kk values.

在《高堡奇人》(The Man in the High Castle)的世界中,共有 mm 种不同的电影结局。

阿本森(Abendsen)拥有一间仓库和一个书架。初始时,书架上按顺序摆放着 nn 部电影。在第 ii 个月,他将执行以下操作:

  1. 清空仓库;
  2. 将 ki⋅mk_i \cdot m 部电影放入仓库,其中每种结局各放 kik_i 部;
  3. 他思考一个问题:若将书架上的所有电影全部放入仓库,再从仓库中随机选取 nn 部电影(从仓库中所有电影中等概率选取),并将这 nn 部电影重新排列后放回书架,那么书架上区间 [li,ri][l_i, r_i] 内的结局序列保持不变的概率是多少?注意,他仅作此思考,书架上的电影实际不会发生任何改变。

请回答阿本森提出的全部问题。

设该概率为分数 PiP_i。记第 ii 个月从仓库中选取 nn 部电影的总方案数为 AiA_i,则 Pi⋅AiP_i \cdot A_i 恒为整数。对每个月 ii,输出 Pi⋅Ai mod 998244353P_i \cdot A_i \bmod 998244353 的值。

998244353998244353 是一个质数,且满足 998244353=119⋅223+1998244353 = 119 \cdot 2^{23} + 1。

保证在整个输入中,不同的 kik_i 值至多有 100100 个。

输入格式

The first line contains three integers nn, mm, and qq (1≤n,m,q≤1051 \le n, m, q \le 10^5, n+q≤105n+q\leq 10^5) — the number of films on the shelf initially, the number of endings, and the number of months.

The second line contains nn integers e1,e2,…,ene_1, e_2, \ldots, e_n (1≤ei≤m1\leq e_i\leq m) — the ending of the ii-th film on the shelf.

Each of the next qq lines contains three integers lil_i, rir_i, and kik_i (1≤li≤ri≤n,0≤ki≤1051 \le l_i \le r_i \le n, 0 \le k_i \le 10^5) — the ii-th query.

It is guaranteed that there will be only no more than 100100 different kk values.

第一行包含三个整数 nn、mm 和 qq(1≤n,m,q≤1051 \le n, m, q \le 10^5,且 n+q≤105n+q\leq 10^5)—— 分别表示书架上初始的电影数量、结局种类数以及月份数。

第二行包含 nn 个整数 e1,e2,…,ene_1, e_2, \ldots, e_n(1≤ei≤m1\leq e_i\leq m)—— 表示书架上第 ii 部电影的结局编号。

接下来的 qq 行中,每行包含三个整数 lil_i、rir_i 和 kik_i(1≤li≤ri≤n1 \le l_i \le r_i \le n,0≤ki≤1050 \le k_i \le 10^5)—— 表示第 ii 个查询。

保证所有查询中不同的 kik_i 值至多有 100100 个。

输出格式

Print the answer for each question in a separate line.

每个问题的答案请单独打印在一行中。

输入输出样例

  • 输入#1

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

    输出#1

    6
    26730
    12150
    4860
  • 输入#2

    5 5 3
    1 2 3 4 5
    1 2 100000
    1 4 4
    3 5 5

    输出#2

    494942218
    13125
    151632

说明/提示

In the first sample in the second query, after adding 2⋅m2 \cdot m films into the storage, the storage will look like this: 1,1,1,2,2,2,3,3,3,4,4,4,4,4{1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4}.

There are 2673026730 total ways of choosing the films so that el,el+1,…,ere_l, e_{l+1}, \ldots, e_r will not be changed, for example, [1,2,3,2,2][1, 2, 3, 2, 2] and [1,2,3,4,3][1, 2, 3, 4, 3] are such ways.

There are 21621602162160 total ways of choosing the films, so you're asked to print (267302162160⋅2162160)mod  998244353=26730(\frac{26730}{2162160} \cdot 2162160) \mod 998244353 = 26730.

在第二个查询的第一个样例中,向存储中添加 2⋅m2 \cdot m 部电影后,存储将变为:1,1,1,2,2,2,3,3,3,4,4,4,4,4{1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4}。

共有 2673026730 种选择电影的方案,使得 el,el+1,…,ere_l, e_{l+1}, \ldots, e_r 保持不变;例如,[1,2,3,2,2][1, 2, 3, 2, 2] 和 [1,2,3,4,3][1, 2, 3, 4, 3] 就是这样的方案。

总共有 21621602162160 种选择电影的方案,因此你需要输出 (267302162160⋅2162160)mod  998244353=26730(\frac{26730}{2162160} \cdot 2162160) \mod 998244353 = 26730。

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

首页