No.2369 Some Products
タグ : / 解いたユーザー数 34
作問者 :
Kak1_n0_tane
/ テスター :
logx
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もしくは右上の雲マークをクリックしてアカウントを作成してください。