CF2204F.Sum of Fractions
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let's call an increase of the fraction yx one of the following operations:
- either increase its numerator x by 1;
- or, if the denominator y>1, decrease its denominator y by 1.
Note that the fraction is not reduced after the increase. For example, if you have a fraction 73 and you decrease its denominator by 1, you get 63, not 21.
Suppose you are given an integer array b1,b2,…,bm and an integer k. You apply the following algorithm:
- Construct the array b11,b21,…,bm1.
- Choose any of the fractions and increase it.
- Repeat the previous step k times (the same fraction can be chosen multiple times).
- Calculate the sum of the resulting fractions.
We will denote MSF(b,k) as the maximum sum of fractions that can be obtained from the array b by applying the increase operation exactly k times.
Let a[l…r] be the subarray al,al+1,…ar of the array a.
You are given two arrays of integers a1,a2,…,an and k1,k2,…,km. For each ki, calculate $$\left( \sum\limits_{l = 1}^{n}{\sum\limits_{r = l}^{n}\mathrm{MSF}(a[l \dots r], k_i)} \right) \bmod 998\,244\,353.$$ In other words, for each ki, calculate the sum of MSF over all subarrays of the array a and output the answer modulo.
我们称对分数 yx 的“增加”为以下两种操作之一:
- 将其分子 x 增加 1;
- 或者,若分母 y>1,则将其分母 y 减少 1。
注意:执行“增加”操作后,分数不约分。例如,若当前分数为 73,将其分母减 1 后得到 63,而非 21。
现给定一个整数数组 b1,b2,…,bm 和一个整数 k。执行如下算法:
- 构造数组 b11,b21,…,bm1。
- 任选其中一个分数并对其执行一次“增加”操作。
- 重复上一步 k 次(同一分数可被多次选择)。
- 计算最终所有分数的和。
我们将 MSF(b,k) 定义为:对数组 b 恰好执行 k 次“增加”操作所能得到的分数之和的最大值。
记 a[l…r] 为数组 a 的子数组 al,al+1,…,ar。
现给定两个整数数组 a1,a2,…,an 和 k1,k2,…,km。对每个 ki,计算
(l=1∑nr=l∑nMSF(a[l…r],ki))mod998244353.
换言之,对每个 ki,计算 MSF 在数组 a 的所有子数组上的总和,并输出该结果对 998244353 取模的值。
输入格式
The first line contains two integers n and m (1≤n,m≤5⋅105) — the sizes of the arrays a and k.
The second line contains n integers a1,a2,…,an (1≤ai≤108) — the array a.
The third line contains m integers k1,k2,…,km (0≤k1≤k2≤⋯≤km≤108) — the array k in non-decreasing order.
第一行包含两个整数 n 和 m(1≤n,m≤5⋅105)—— 分别为数组 a 和 k 的长度。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤108)—— 数组 a。
第三行包含 m 个整数 k1,k2,…,km(0≤k1≤k2≤⋯≤km≤108)—— 按非递减顺序排列的数组 k。
输出格式
For each ki, output a single integer — the sum of MSF over all subarrays modulo 998244353.
It can be proven that the answer can be represented as an irreducible fraction QP, where Q≡0(mod998244353). Accordingly, output the answer in the form P⋅Q−1(mod998244353).
对于每个 ki,输出一个整数——即所有子数组的 MSF 之和对 998244353 取模的结果。
可以证明,该答案可表示为既约分数 QP,其中 Q≡0(mod998244353)。因此,请以 P⋅Q−1(mod998244353) 的形式输出答案。
输入输出样例
输入#1
5 4 2 3 5 2 3 0 1 2 10
输出#1
232923695 332748137 931694761 133099397
说明/提示
The answers for the corresponding k are: 30379, 358, 15473, and 152249.
对应 k 的答案为:30379、358、15473 和 152249。
输入解题思路,AI测评打分。不知道怎么写?