CF2204F.Sum of Fractions

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Let's call an increase of the fraction xy\frac{x}{y} one of the following operations:

  • either increase its numerator xx by 11;
  • or, if the denominator y>1y \gt 1, decrease its denominator yy by 11.

Note that the fraction is not reduced after the increase. For example, if you have a fraction 37\frac{3}{7} and you decrease its denominator by 11, you get 36\frac{3}{6}, not 12\frac{1}{2}.

Suppose you are given an integer array b1,b2,…,bmb_1, b_2, \dots, b_m and an integer kk. You apply the following algorithm:

  1. Construct the array 1b1,1b2,…,1bm\frac{1}{b_1}, \frac{1}{b_2}, \dots, \frac{1}{b_m}.
  2. Choose any of the fractions and increase it.
  3. Repeat the previous step kk times (the same fraction can be chosen multiple times).
  4. Calculate the sum of the resulting fractions.

We will denote MSF(b,k)\mathrm{MSF}(b, k) as the maximum sum of fractions that can be obtained from the array bb by applying the increase operation exactly kk times.

Let a[l…r]a[l \dots r] be the subarray al,al+1,…ara_l, a_{l + 1}, \dots a_r of the array aa.

You are given two arrays of integers a1,a2,…,ana_1, a_2, \dots, a_n and k1,k2,…,kmk_1, k_2, \dots, k_m. For each kik_i, 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 kik_i, calculate the sum of MSF\mathrm{MSF} over all subarrays of the array aa and output the answer modulo.

我们称对分数 xy\frac{x}{y} 的“增加”为以下两种操作之一:

  • 将其分子 xx 增加 11;
  • 或者,若分母 y>1y > 1,则将其分母 yy 减少 11。

注意:执行“增加”操作后,分数不约分。例如,若当前分数为 37\frac{3}{7},将其分母减 11 后得到 36\frac{3}{6},而非 12\frac{1}{2}。

现给定一个整数数组 b1,b2,…,bmb_1, b_2, \dots, b_m 和一个整数 kk。执行如下算法:

  1. 构造数组 1b1,1b2,…,1bm\frac{1}{b_1}, \frac{1}{b_2}, \dots, \frac{1}{b_m}。
  2. 任选其中一个分数并对其执行一次“增加”操作。
  3. 重复上一步 kk 次(同一分数可被多次选择)。
  4. 计算最终所有分数的和。

我们将 MSF(b,k)\mathrm{MSF}(b, k) 定义为:对数组 bb 恰好执行 kk 次“增加”操作所能得到的分数之和的最大值。

记 a[l…r]a[l \dots r] 为数组 aa 的子数组 al,al+1,…,ara_l, a_{l + 1}, \dots, a_r。

现给定两个整数数组 a1,a2,…,ana_1, a_2, \dots, a_n 和 k1,k2,…,kmk_1, k_2, \dots, k_m。对每个 kik_i,计算

(∑l=1n∑r=lnMSF(a[l…r],ki)) mod 998 244 353.\left( \sum\limits_{l = 1}^{n}{\sum\limits_{r = l}^{n}\mathrm{MSF}(a[l \dots r], k_i)} \right) \bmod 998\,244\,353.

换言之,对每个 kik_i,计算 MSF\mathrm{MSF} 在数组 aa 的所有子数组上的总和,并输出该结果对 998 244 353998\,244\,353 取模的值。

输入格式

The first line contains two integers nn and mm (1≤n,m≤5⋅1051 \le n, m \le 5 \cdot 10^5) — the sizes of the arrays aa and kk.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1081 \le a_i \le 10^8) — the array aa.

The third line contains mm integers k1,k2,…,kmk_1, k_2, \dots, k_m (0≤k1≤k2≤⋯≤km≤1080 \le k_1 \le k_2 \le \dots \le k_m \le 10^8) — the array kk in non-decreasing order.

第一行包含两个整数 nn 和 mm(1≤n,m≤5⋅1051 \le n, m \le 5 \cdot 10^5)—— 分别为数组 aa 和 kk 的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1081 \le a_i \le 10^8)—— 数组 aa。

第三行包含 mm 个整数 k1,k2,…,kmk_1, k_2, \dots, k_m(0≤k1≤k2≤⋯≤km≤1080 \le k_1 \le k_2 \le \dots \le k_m \le 10^8)—— 按非递减顺序排列的数组 kk。

输出格式

For each kik_i, output a single integer — the sum of MSF\mathrm{MSF} over all subarrays modulo 998 244 353998\,244\,353.

It can be proven that the answer can be represented as an irreducible fraction PQ\frac{P}{Q}, where Q≢0(mod998 244 353)Q \not\equiv 0 \pmod{998\,244\,353}. Accordingly, output the answer in the form P⋅Q−1(mod998 244 353)P \cdot Q^{-1} \pmod{998\,244\,353}.

对于每个 kik_i,输出一个整数——即所有子数组的 MSF\mathrm{MSF} 之和对 998 244 353998\,244\,353 取模的结果。

可以证明,该答案可表示为既约分数 PQ\frac{P}{Q},其中 Q≢0(mod998 244 353)Q \not\equiv 0 \pmod{998\,244\,353}。因此,请以 P⋅Q−1(mod998 244 353)P \cdot Q^{-1} \pmod{998\,244\,353} 的形式输出答案。

输入输出样例

  • 输入#1

    5 4
    2 3 5 2 3
    0 1 2 10

    输出#1

    232923695
    332748137
    931694761
    133099397

说明/提示

The answers for the corresponding kk are: 37930\frac{379}{30}, 583\frac{58}{3}, 47315\frac{473}{15}, and 224915\frac{2249}{15}.

对应 kk 的答案为:37930\frac{379}{30}、583\frac{58}{3}、47315\frac{473}{15} 和 224915\frac{2249}{15}。

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

首页