CF1641E.Special Positions
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a of length n . Also you are given m distinct positions p1,p2,…,pm ( 1≤pi≤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 fracpq , where p and q are integers and qneq0 (mod M ). Output the integer equal to pcdotq−1 (mod M ). In other words, output such integer x that 0 \\leq x < M and xcdotq=p (mod M$$).
输入格式
The first line contains two integers n and m ( 1≤m≤n≤105 ).
The second line contains n integers a1,a2,…,an ( 0≤ai<998244353 ).
The third line contains m distinct integers p1,p2,…,pm ( 1≤pi≤n ).
For every 1≤i<m it is guaranteed that pi<pi+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 1 is choosen, than the value equals to 1⋅0+2⋅1+3⋅2+4⋅3=20 .
- If only 4 is choosen, than the value equals to 1⋅3+2⋅2+3⋅1+4⋅0=10 .
- If both positions are chosen, than the value equals to 1⋅0+2⋅1+3⋅1+4⋅0=5 .
The answer to the problem is 320+10+5=335=665496247 (modulo 998244353 ).