AT_abc468_e.Sum of Average

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a positive integer NN and a length-NN integer sequence A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N).

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

Find ∑1≤l≤r≤Nf(l,r)\displaystyle \sum_{1\le l\le r\le N} f(l,r), modulo 998244353998244353.

Definition of a rational number modulo 998244353998244353

Under the constraints of this problem, it can be proved that the rational number to be found is always an irreducible fraction PQ\frac{P}{Q} such that Q≢0(mod998244353)Q {{}\not\equiv{}} 0 \pmod{998244353}. Thus, there is a unique integer RR such that R×Q≡P(mod998244353),0≤R<998244353R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353. Output this RR.

给定一个正整数 NN 和一个长度为 NN 的整数序列 A=(A1,A2,…,AN)A=(A_1,A_2,\ldots,A_N)。

定义 f(l,r)f(l,r) 为 Al,Al+1,…,ArA_l,A_{l+1},\ldots,A_r 的(算术)平均值。

求 ∑1≤l≤r≤Nf(l,r)\displaystyle \sum_{1\le l\le r\le N} f(l,r) 对 998244353998244353 取模的结果。

有理数对 998244353998244353 取模的定义

在本题的约束条件下,可以证明所求的有理数恒为一个既约分数 PQ\frac{P}{Q},且满足 Q≢0(mod998244353)Q {{}\not\equiv{}} 0 \pmod{998244353}。因此,存在唯一的整数 RR 满足 R×Q≡P(mod998244353)R \times Q \equiv P \pmod{998244353} 且 0≤R<9982443530 \leq R < 998244353。请输出该 RR。

输入格式

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

NN
A1A_1 A2A_2 …\ldots ANA_N

输入从标准输入中按以下格式给出:

NN
A1A_1 A2A_2 …\ldots ANA_N

输出格式

Output the answer.

输出答案。

输入输出样例

  • 输入#1

    2
    2 3

    输出#1

    499122184
  • 输入#2

    6
    1 2 3 4 5 6

    输出#2

    499122250
  • 输入#3

    9
    3 1 4 1 5 9 2 6 5

    输出#3

    855638200

说明/提示

Sample 1 Explanation:
We have f(1,1)=2,f(1,2)=2+32=52,f(2,2)=3\displaystyle f(1,1)=2,f(1,2)=\frac{2+3}2=\frac52,f(2,2)=3. Thus, ∑1≤l≤r≤Nf(l,r)=2+52+3=152\displaystyle \sum_{1\le l\le r\le N} f(l,r)=2+\frac52+3=\frac{15}2.

152\displaystyle \frac{15}2 in modulo-998244353998244353 expression is 499122184499122184, so output 499122184499122184.

Constraints

  • 1≤N≤5×1051\le N\le 5\times 10^5
  • 0≤Ai<9982443530\le A_i < 998244353
  • All input values are integers.

样例 1 解释:
我们有 f(1,1)=2,f(1,2)=2+32=52,f(2,2)=3\displaystyle f(1,1)=2,f(1,2)=\frac{2+3}2=\frac52,f(2,2)=3。因此,∑1≤l≤r≤Nf(l,r)=2+52+3=152\displaystyle \sum_{1\le l\le r\le N} f(l,r)=2+\frac52+3=\frac{15}2。

152\displaystyle \frac{15}2 在模 998244353998244353 意义下的值为 499122184499122184,故输出 499122184499122184。

约束条件

  • 1≤N≤5×1051\le N\le 5\times 10^5
  • 0≤Ai<9982443530\le A_i < 998244353
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页