Codeforces Round 773 (Div. 1)
E
Special Positions
Codeforces
3300
原题
← DF →
翻译中…

You are given an array $a$ of length $n$. Also you are given $m$ distinct positions $p_1, p_2, \ldots, p_m$ ($1 \leq p_i \leq n$).

翻译中…

A non-empty subset of these positions $T$ 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, $a_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\,353$. More formally, let $M = 998\,244\,353$. It can be shown that the answer can be represented as an irreducible fraction $\frac{p}{q}$, where $p$ and $q$ are integers and $q \neq 0$ (mod $M$). Output the integer equal to $p \cdot q^{-1}$ (mod $M$). In other words, output such integer $x$ that $0 \leq x \lt M$ and $x \cdot q = p$ (mod $M$).

翻译中…

Input

翻译中…

The first line contains two integers $n$ and $m$ ($1 \leq m \leq n \leq 10^5$).

翻译中…

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i \lt 998\,244\,353$).

翻译中…

The third line contains $m$ distinct integers $p_1, p_2, \ldots, p_m$ ($1 \leq p_i \le n$).

翻译中…

For every $1 \leq i \lt m$ it is guaranteed that $p_i \lt p_{i+1}$.

翻译中…

Output

翻译中…

Print a single integer — the answer to the problem.

翻译中…

Note

翻译中…

In the first test:

翻译中…
  • If only $1$ is choosen, than the value equals to $1 \cdot 0 + 2 \cdot 1 + 3 \cdot 2 + 4 \cdot 3 = 20$.
  • If only $4$ is choosen, than the value equals to $1 \cdot 3 + 2 \cdot 2 + 3 \cdot 1 + 4 \cdot 0 = 10$.
  • If both positions are chosen, than the value equals to $1 \cdot 0 + 2 \cdot 1 + 3 \cdot 1 + 4 \cdot 0 = 5$.
翻译中…

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

翻译中…

样例

Input #1
4 2
1 2 3 4
1 4
Output #1
665496247
InputCopy OutputCopy
Input #2
6 6
4 2 4 2 4 2
1 2 3 4 5 6
Output #2
855638030
InputCopy OutputCopy
题目信息
题号
1641E
时间限制
5 s
内存限制
512 MB
标签
组合数学
分治
FFT
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。