P13978 Introduction to Sequence Block Decomposition 3
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 queries for the predecessor of a value $x$ in a range (the largest element smaller than $x$).
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 value of the predecessor of $c$ in $[l, r]$ (output $-1$ if it does not exist).
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 100000$, $-2^{31} \leq a_i, c, \mathrm{ans} \leq 2^{31}-1$.
Subtask 2 (60 points): $1 \leq n \leq 200000$, $-2^{31} \leq a_i, c, \mathrm{ans} \leq 2^{31}-1$.
For all testdata, $1 \leq n \leq 200000$ and $-2^{31} \leq a_i, c, \mathrm{ans} \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$.
Translated by QwenWork