SP19543 GSS8 - Can you answer these queries VIII

Description

You are given a sequence $A_0, A_1, \dots, A_{N-1}$. ($0 \le A_i < 2^{32}$) You are to perform $Q$ operations: 1. $\text{I}\;\textit{pos}\;\textit{val}$: insert number $\textit{val}$ in the sequence before the element with index $\textit{pos}$. ($0 \le \textit{val} < 2^{32}$; if $\textit{pos} = N'$, then you should add the number to the end of the sequence) 2. $\text{D}\;\textit{pos}$: delete the element with index $\textit{pos}$ from the sequence. 3. $\text{R}\;\textit{pos}\;\textit{val}$: replace the element with index $\textit{pos}$ by $\textit{val}$. ($0 \le \textit{val} < 2^{32}$) 4. $\text{Q}\;\textit{l}\;\textit{r}\;\textit{k}$: answer $\sum_{i=l}^{r} A_i \cdot (i - l + 1)^k \pmod{2^{32}}$, for $l \le i \le r$. ($0 \le k \le 10$) Here, $N'$ denotes the current length of the sequence.

Input Format

The first line contains an integer $N$ ($1 \le N \le 10^5$), the initial length of the sequence. The second line contains $N$ integers $A_0, A_1, \dots, A_{N-1}$ ($0 \le A_i < 2^{32}$). The third line contains an integer $Q$ ($1 \le Q \le 10^5$), the number of operations. Each of the next $Q$ lines describes an operation in one of the following formats: - `I pos val` - `D pos` - `R pos val` - `Q l r k` It is guaranteed that all indices in the operations are valid for the current state of the sequence. Specifically: - For `I`, $0 \le \textit{pos} \le N'$. - For `D` and `R`, $0 \le \textit{pos} < N'$. - For `Q`, $0 \le l \le r < N'$.

Output Format

For each query operation (`Q`), print the result on a new line.