問題一覧 > 通常問題

No.2369 Some Products

レベル : / AI推定難易度 : 1900 / 実行時間制限 : 1ケース 2.500秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 34
作問者 : Kak1_n0_tane / テスター : logx shobonvip Carpenters-Cat comavius
お気に入りにしたユーザー ProblemId : 9609 / 自分の提出
問題文最終更新日: 2023-06-30 21:14:23
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 395 (順位表) の他の問題:

Problem Statement

Pina likes the formula $\displaystyle\sum_{1\leq i<j\leq n}ij=\frac{1}{2}\left(\left(\sum_{k=1}^{n}k\right)^2 - \left(\sum_{k=1}^{n}k^2\right)\right)$.

By the way, you are given a positive integer $N$ and an integer sequence $\{P_n\}$ of length $N$.
Answer the following $Q$ queries.
・Given $2$ integers $A, B$ satisfying $1 \leq A < B \leq N$ and an integer $K$ satisfying $1 \leq K \leq B-A+1$, for every way of choosing $K$ terms from $P_A, P_{A+1}, \dots, P_B$, compute the product of the $K$ terms, and output the sum of those products.

Input

$N$
$P_1\ \ P_2\ \ \cdots\ P_N$
$Q$
$A_1\ \ B_1\ \ K_1$
$A_2\ \ B_2\ \ K_2$
$\vdots$
$A_Q\ \ B_Q\ \ K_Q$

・$2\leq N\leq 5000$
・$-10^9\leq P_i\leq 10^9\ (1\leq i\leq N)$
・$1\leq Q\leq 5000$
・$1\leq A_i < B_i\leq N (1\leq i\leq Q)$
・$1\leq K_i\leq B_i-A_i+1 (1\leq i\leq Q)$
・All input values are integers.

Output

Output the answer to each query on its own line, and print a newline at the end.
Since the answer can be very large, output the remainder when the answer is divided by $998244353$ (an integer at least $0$ and less than $998244353$).

Sample

Sample 1
Input
5
1 2 3 4 5
3
1 5 1
2 4 2
3 5 3
Output
15
26
60

In query $1$, compute $1+2+3+4+5$.
In query $2$, compute $2\times3+3\times4+4\times2$.
In query $3$, compute $3\times4\times5$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。