33OJ
登录 注册

#P13978. 数列分块入门 3

数列分块入门 3

Background

The constraints of the testdata in Luogu's "Introduction to Sequence Block Decomposition" series differ from those of the original problems.

Problem Description

You are given a sequence of length nn and nn operations. The operations involve range addition and queries for the predecessor of a value xx in a range (the largest element smaller than xx).

Input Format

The first line contains one integer nn.

The second line contains nn integers, where the ii-th integer is aia_i, separated by spaces.

Then nn lines follow, each containing a query. Each line contains four integers opt\mathrm{opt}, ll, rr, cc, separated by spaces.

If opt=0\mathrm{opt} = 0, it means that cc is added to every number in [l,r][l, r].

If opt=1\mathrm{opt} = 1, it means that you should query the value of the predecessor of cc in [l,r][l, r] (output −1-1 if it does not exist).

Output Format

For each query, output one integer on a single line giving the answer.

4
1 2 2 3
0 1 3 1
1 1 4 4
0 1 2 2
1 1 2 4
3
-1

Hint

Subtasks

Subtask 1 (40 points): 1≤n≤1000001 \leq n \leq 100000, −231≤ai,c,ans≤231−1-2^{31} \leq a_i, c, \mathrm{ans} \leq 2^{31}-1.

Subtask 2 (60 points): 1≤n≤2000001 \leq n \leq 200000, −231≤ai,c,ans≤231−1-2^{31} \leq a_i, c, \mathrm{ans} \leq 2^{31}-1.

For all testdata, 1≤n≤2000001 \leq n \leq 200000 and −231≤ai,c,ans≤231−1-2^{31} \leq a_i, c, \mathrm{ans} \leq 2^{31}-1. 1≤l≤r≤n1 \leq l \leq r \leq n. opt∈{0,1}\mathrm{opt} \in \{0,1\}, 1≤l≤r≤n1 \leq l \leq r \leq n. After each operation every aia_i satisfies −231≤ai≤231−1-2^{31} \leq a_i \leq 2^{31}-1.

Translated by QwenWork