A14948 | Special Positions
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.</p><p>Find the expected value of this sum.</p><p>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 < M$ and $x \\cdot q = p$ (mod $M$$$).
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.</p><p>Find the expected value of this sum.</p><p>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 < M$ and $x \\cdot q = p$ (mod $M$$$).
输入格式
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 < 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 < m$ it is guaranteed that $p_i < p_{i+1}$ .
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $0 \leq a_i < 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 < m$ it is guaranteed that $p_i < 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 $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$ ).
- 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$ ).
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted