CF1017H.The Films
普及/提高-
通过率:0%
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 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.
输出格式
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 .