AtCoder Beginner Contest 468
E
Sum of Average
AtCoder
⌀ 1038
原题
← CF →

Sum of AverageAI (CI翻译)

Problem Statement

You are given a positive integer $N$ and a length-$N$ integer sequence $A=(A_1,A_2,\ldots,A_N)$.

Define $f(l,r)$ as the (arithmetic) mean of $A_l,A_{l+1},\ldots,A_r$.

Find $\displaystyle \sum_{1\le l\le r\le N} f(l,r)$, modulo $998244353$.

Definition of a rational number modulo $998244353$ Under the constraints of this problem, it can be proved that the rational number to be found is always an irreducible fraction $\frac{P}{Q}$ such that $Q {{}\not\equiv{}} 0 \pmod{998244353}$. Thus, there is a unique integer $R$ such that $R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353$. Output this $R$.

Constraints

  • $1\le N\le 5\times 10^5$
  • $0\le A_i < 998244353$
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 \ldots A_N

Output

Output the answer.

{"titleZh":"平均值之和","bodyZh":"## 题目描述\n\n给定一个正整数 $N$ 和一个长度为 $N$ 的整数序列 $A=(A_1,A_2,\\ldots,A_N)$。\n\n定义 $f(l,r)$ 为 $A_l,A_{l+1},\\ldots,A_r$ 的(算术)平均值。\n\n求 $\displaystyle \\sum_{1\\le l\\le r\\le N} f(l,r)$ 对 $998244353$ 取模后的结果。\n\n模 $998244353$ 意义下的有理数定义:在本题的约束条件下,可以证明,所求有理数始终可以表示为既约分数 $\\frac{P}{Q}$,且满足 $Q {{}\\not\\equiv{}} 0 \\pmod{998244353}$。因此,存在唯一的整数 $R$,满足 $R \\times Q \\equiv P \\pmod{998244353}$ 且 $0 \\le R < 998244353$。请输出该 $R$。\n\n## 约束条件\n\n- $1\\le N\\le 5\\times 10^5$\n- $0\\le A_i < 998244353$\n- 所有输入值均为整数。\n\n## 输入格式\n\n输入从标准输入按以下格式给出:\n\n\nN\nA_1 A_2 \\ldots A_N\n\n\n## 输出格式\n\n输出答案。"}AI (CI翻译)

样例

Input #1
2
2 3
Output #1
499122184
We have $\displaystyle f(1,1)=2,f(1,2)=\frac{2+3}2=\frac52,f(2,2)=3$. Thus, $\displaystyle \sum_{1\le l\le r\le N} f(l,r)=2+\frac52+3=\frac{15}2$. $\displaystyle \frac{15}2$ in modulo-$998244353$ expression is $499122184$, so output $499122184$.
Input #2
6
1 2 3 4 5 6
Output #2
499122250
Input #3
9
3 1 4 1 5 9 2 6 5
Output #3
855638200
题目信息
题号
abc468_e
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。