CF1641E.Special Positions

NOI/NOI+/CTSC

通过率:0%

时间限制:5.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given an array aa of length nn. Also you are given mm distinct positions p1,p2,…,pmp_1, p_2, \ldots, p_m (1≤pi≤n1 \leq p_i \leq n).

A non-empty subset of these positions TT is randomly selected with equal probability and the following value is calculated: $$\sum_{i=1}^{n} (a_i \cdot \min_{j \in T} \left|i - j\right|).$$ In other word, for each index of the array, aia_i and the distance to the closest chosen position are multiplied, and then these values are summed up.

Find the expected value of this sum.

This value must be found modulo 998 244 353998\,244\,353. More formally, let M=998 244 353M = 998\,244\,353. It can be shown that the answer can be represented as an irreducible fraction pq\frac{p}{q}, where pp and qq are integers and q≠0q \neq 0 (mod MM). Output the integer equal to p⋅q−1p \cdot q^{-1} (mod MM). In other words, output such integer xx that 0≤x<M0 \leq x \lt M and x⋅q=px \cdot q = p (mod MM).

给你一个长度为 nn 的数组 aa,以及 mm 个互不相同的位置 p1,p2,…,pmp_1, p_2, \ldots, p_m(满足 1≤pi≤n1 \leq p_i \leq n)。

从这些位置中非空子集 TT 被等概率随机选取,并计算如下值:

∑i=1n(ai⋅min⁡j∈T∣i−j∣).\sum_{i=1}^{n} \left(a_i \cdot \min_{j \in T} \left|i - j\right|\right).

换言之,对数组的每个下标 ii,将 aia_i 与它到所选位置集合 TT 中最近位置的距离相乘,再将所有这些乘积求和。

请计算该和的期望值。

答案需对 998 244 353998\,244\,353 取模。更准确地说,令 M=998 244 353M = 998\,244\,353。可以证明答案可表示为既约分数 pq\frac{p}{q},其中 pp 和 qq 为整数,且 q≢0(modM)q \not\equiv 0 \pmod{M}。请输出整数 p⋅q−1 mod Mp \cdot q^{-1} \bmod M。即,输出满足 0≤x<M0 \leq x < M 且 x⋅q≡p(modM)x \cdot q \equiv p \pmod{M} 的整数 xx。

输入格式

The first line contains two integers nn and mm (1≤m≤n≤1051 \leq m \leq n \leq 10^5).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai<998 244 3530 \leq a_i \lt 998\,244\,353).

The third line contains mm distinct integers p1,p2,…,pmp_1, p_2, \ldots, p_m (1≤pi≤n1 \leq p_i \le n).

For every 1≤i<m1 \leq i \lt m it is guaranteed that pi<pi+1p_i \lt p_{i+1}.

第一行包含两个整数 nn 和 mm(1≤m≤n≤1051 \leq m \leq n \leq 10^5)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai<998 244 3530 \leq a_i \lt 998\,244\,353)。

第三行包含 mm 个互不相同的整数 p1,p2,…,pmp_1, p_2, \ldots, p_m(1≤pi≤n1 \leq p_i \le n)。

对于每个 1≤i<m1 \leq i \lt m,保证有 pi<pi+1p_i \lt p_{i+1}。

输出格式

Print a single integer — the answer to the problem.

输出一个整数——该问题的答案。

输入输出样例

  • 输入#1

    4 2
    1 2 3 4
    1 4

    输出#1

    665496247
  • 输入#2

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

    输出#2

    855638030

说明/提示

In the first test:

  • If only 11 is choosen, than the value equals to 1⋅0+2⋅1+3⋅2+4⋅3=201 \cdot 0 + 2 \cdot 1 + 3 \cdot 2 + 4 \cdot 3 = 20.
  • If only 44 is choosen, than the value equals to 1⋅3+2⋅2+3⋅1+4⋅0=101 \cdot 3 + 2 \cdot 2 + 3 \cdot 1 + 4 \cdot 0 = 10.
  • If both positions are chosen, than the value equals to 1⋅0+2⋅1+3⋅1+4⋅0=51 \cdot 0 + 2 \cdot 1 + 3 \cdot 1 + 4 \cdot 0 = 5.

The answer to the problem is 20+10+53=353=665 496 247\frac{20 + 10 + 5}{3} = \frac{35}{3} = 665\,496\,247 (modulo 998 244 353998\,244\,353).

在第一个测试中:

  • 如果只选择 11,则值为 1⋅0+2⋅1+3⋅2+4⋅3=201 \cdot 0 + 2 \cdot 1 + 3 \cdot 2 + 4 \cdot 3 = 20。
  • 如果只选择 44,则值为 1⋅3+2⋅2+3⋅1+4⋅0=101 \cdot 3 + 2 \cdot 2 + 3 \cdot 1 + 4 \cdot 0 = 10。
  • 如果同时选择这两个位置,则值为 1⋅0+2⋅1+3⋅1+4⋅0=51 \cdot 0 + 2 \cdot 1 + 3 \cdot 1 + 4 \cdot 0 = 5。

该问题的答案为 20+10+53=353=665 496 247\frac{20 + 10 + 5}{3} = \frac{35}{3} = 665\,496\,247(对 998 244 353998\,244\,353 取模)。

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

首页