P13979 Introduction to Sequence Block Decomposition 4
Background
The constraints of the testdata in Luogu's "Introduction to Sequence Block Decomposition" series differ from those of the original problems.
Description
You are given a sequence of length $n$ and $n$ operations. The operations involve range addition and range sum.
Input Format
The first line contains one integer $n$.
The second line contains $n$ integers, where the $i$-th integer is $a_i$, separated by spaces.
Then $n$ lines follow, each containing a query. Each line contains four integers $\mathrm{opt}$, $l$, $r$, $c$, separated by spaces.
If $\mathrm{opt} = 0$, it means that $c$ is added to every number in $[l, r]$.
If $\mathrm{opt} = 1$, it means that you should query the sum of all numbers in $[l, r]$ modulo $(c+1)$. You need to output a **non-negative remainder**.
Output Format
For each query, output one integer on a single line giving the answer.
Explanation/Hint
### Subtasks
Subtask 1 (40 points): $1 \leq n \leq 50000$, $-2^{31} \leq a_i, c \leq 2^{31}-1$.
Subtask 2 (60 points): $1 \leq n \leq 3\times 10^5$, $-2^{31} \leq a_i, c \leq 2^{31}-1$.
For all testdata, $1 \leq n \leq 3\times 10^5$ and $-2^{31} \leq a_i, c \leq 2^{31}-1$. $1 \leq l \leq r \leq n$. $\mathrm{opt} \in \{0,1\}$, $1 \leq l \leq r \leq n$. After each operation every $a_i$ satisfies $-2^{31} \leq a_i \leq 2^{31}-1$. In particular, the testdata guarantee that $c \geq 0$ when $\mathrm{opt}=1$.
Translated by QwenWork