No.3045 反復重み付き累積和
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. Show the original
Story
nauclhlt is no longer satisfied with ordinary prefix sums. Nor can an ordinary number of prefix sum iterations satisfy him.
For example, how about taking the prefix sum $10^9$ times...
Problem Statement
We define the prefix sum with weight $K$ of a sequence $P$ as the sequence $Q$ of length $|P|$ satisfying the following.
- $\displaystyle Q_i=\sum_{j=1}^i K^{i-j}P_j\ (1\leq i\leq |P|)$
Here, $|P|$ is the length of the sequence $P$.
You are given a sequence $A=(A_1, A_2, \cdots, A_N)$ of length $N$.
Process $Q$ queries of the following forms in order.
1 k x: Repeat the operation "replace $A$ with the prefix sum with weight $k$ of $A$" $x$ times.2 x: Print the value of $A_x$ modulo $998244353$.
Input
$N\ Q$ $A_1\ A_2\ \cdots\ A_N$ $query_1$ $query_2$ $\vdots$ $query_Q$
Each query is given in one of the following formats.
$1\ k\ x$
$2\ x$
- $1\leq N\leq 2000$
- $0\leq A_i\lt 998244353$
- $1\leq Q\leq 2000$
- For queries of the form
1 k x, $1\leq k\lt 998244353, 1\leq x\leq 10^9$ - For queries of the form
2 x, $1\leq x\leq N$ - At least 1 query of the form
2 xis given. - All inputs are integers.
Output
Let $m$ be the number of queries of the form 2 x, and print $m$ lines.
On the $i(1\leq i\leq m)$-th line, print the answer to the $i$-th such query.
Print a newline at the end.
Sample
Sample 1
Input
4 3 3 1 4 1 2 3 1 2 1 2 3
Output
4 18
- For the 1st query, $A_3=4$, so print
4. - For the 2nd query, the prefix sum with weight $2$ of $A$ is $(3, 7, 18, 37)$. Thus, replace $A$ with this sequence.
- For the 3rd query, $A_3=18$, so print
18.
Sample 2
Input
3 2 1 1 2 1 3 2 2 2
Output
7
The prefix sum with weight $3$ of $A$ is $(1, 4, 14)$. Taking the prefix sum with weight $3$ of this sequence gives $(1, 7, 35)$. Thus, after the 1st query, $A=(1, 7, 35)$.
In the 2nd query, from the above result, $A_2=7$, so print 7.
Sample 3
Input
10 2 0 9 9 8 2 4 4 3 5 3 1 998244352 998244353 2 10
Output
3
Print the value modulo $998244353$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
nauclhlt
naniwazu