CF1017H.The Films
NOI/NOI+/CTSC
通过率:0%
时间限制:5.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In "The Man in the High Castle" world, there are m different film endings.
Abendsen owns a storage and a shelf. At first, he has n ordered films on the shelf. In the i-th month he will do:
- Empty the storage.
- Put ki⋅m films into the storage, ki films for each ending.
- He will think about a question: if he puts all the films from the shelf into the storage, then randomly picks n 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] 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 Pi. Let's say that the total number of ways to take n films from the storage for i-th month is Ai, so Pi⋅Ai is always an integer. Print for each month Pi⋅Ai(mod998244353).
998244353 is a prime number and it is equal to 119⋅223+1.
It is guaranteed that there will be only no more than 100 different k values.
在《高堡奇人》(The Man in the High Castle)的世界中,共有 m 种不同的电影结局。
阿本森(Abendsen)拥有一间仓库和一个书架。初始时,书架上按顺序摆放着 n 部电影。在第 i 个月,他将执行以下操作:
- 清空仓库;
- 将 ki⋅m 部电影放入仓库,其中每种结局各放 ki 部;
- 他思考一个问题:若将书架上的所有电影全部放入仓库,再从仓库中随机选取 n 部电影(从仓库中所有电影中等概率选取),并将这 n 部电影重新排列后放回书架,那么书架上区间 [li,ri] 内的结局序列保持不变的概率是多少?注意,他仅作此思考,书架上的电影实际不会发生任何改变。
请回答阿本森提出的全部问题。
设该概率为分数 Pi。记第 i 个月从仓库中选取 n 部电影的总方案数为 Ai,则 Pi⋅Ai 恒为整数。对每个月 i,输出 Pi⋅Aimod998244353 的值。
998244353 是一个质数,且满足 998244353=119⋅223+1。
保证在整个输入中,不同的 ki 值至多有 100 个。
输入格式
The first line contains three integers n, m, and q (1≤n,m,q≤105, n+q≤105) — the number of films on the shelf initially, the number of endings, and the number of months.
The second line contains n integers e1,e2,…,en (1≤ei≤m) — the ending of the i-th film on the shelf.
Each of the next q lines contains three integers li, ri, and ki (1≤li≤ri≤n,0≤ki≤105) — the i-th query.
It is guaranteed that there will be only no more than 100 different k values.
第一行包含三个整数 n、m 和 q(1≤n,m,q≤105,且 n+q≤105)—— 分别表示书架上初始的电影数量、结局种类数以及月份数。
第二行包含 n 个整数 e1,e2,…,en(1≤ei≤m)—— 表示书架上第 i 部电影的结局编号。
接下来的 q 行中,每行包含三个整数 li、ri 和 ki(1≤li≤ri≤n,0≤ki≤105)—— 表示第 i 个查询。
保证所有查询中不同的 ki 值至多有 100 个。
输出格式
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⋅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.
There are 26730 total ways of choosing the films so that el,el+1,…,er will not be changed, for example, [1,2,3,2,2] and [1,2,3,4,3] are such ways.
There are 2162160 total ways of choosing the films, so you're asked to print (216216026730⋅2162160)mod998244353=26730.
在第二个查询的第一个样例中,向存储中添加 2⋅m 部电影后,存储将变为:1,1,1,2,2,2,3,3,3,4,4,4,4,4。
共有 26730 种选择电影的方案,使得 el,el+1,…,er 保持不变;例如,[1,2,3,2,2] 和 [1,2,3,4,3] 就是这样的方案。
总共有 2162160 种选择电影的方案,因此你需要输出 (216216026730⋅2162160)mod998244353=26730。
输入解题思路,AI测评打分。不知道怎么写?