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\n\n## 输出格式\n\n输出答案。"}AI (CI翻译)\nN\nA_1 A_2 \\ldots A_N\n
样例
2
2 3
499122184
6
1 2 3 4 5 6
499122250
9
3 1 4 1 5 9 2 6 5
855638200
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。