CF1641E.Special Positions
NOI/NOI+/CTSC
通过率:0%
时间限制:5.00s
内存限制:512MB
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, ai 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 998244353. More formally, let M=998244353. It can be shown that the answer can be represented as an irreducible fraction qp, where p and q are integers and q=0 (mod M). Output the integer equal to p⋅q−1 (mod M). In other words, output such integer x that 0≤x<M and x⋅q=p (mod M).
给你一个长度为 n 的数组 a,以及 m 个互不相同的位置 p1,p2,…,pm(满足 1≤pi≤n)。
从这些位置中非空子集 T 被等概率随机选取,并计算如下值:
i=1∑n(ai⋅j∈Tmin∣i−j∣).
换言之,对数组的每个下标 i,将 ai 与它到所选位置集合 T 中最近位置的距离相乘,再将所有这些乘积求和。
请计算该和的期望值。
答案需对 998244353 取模。更准确地说,令 M=998244353。可以证明答案可表示为既约分数 qp,其中 p 和 q 为整数,且 q≡0(modM)。请输出整数 p⋅q−1modM。即,输出满足 0≤x<M 且 x⋅q≡p(modM) 的整数 x。
输入格式
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.
第一行包含两个整数 n 和 m(1≤m≤n≤105)。
第二行包含 n 个整数 a1,a2,…,an(0≤ai<998244353)。
第三行包含 m 个互不相同的整数 p1,p2,…,pm(1≤pi≤n)。
对于每个 1≤i<m,保证有 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).
在第一个测试中:
- 如果只选择 1,则值为 1⋅0+2⋅1+3⋅2+4⋅3=20。
- 如果只选择 4,则值为 1⋅3+2⋅2+3⋅1+4⋅0=10。
- 如果同时选择这两个位置,则值为 1⋅0+2⋅1+3⋅1+4⋅0=5。
该问题的答案为 320+10+5=335=665496247(对 998244353 取模)。
输入解题思路,AI测评打分。不知道怎么写?