33OJ
登录 注册

#P13979. 数列分块入门 4

数列分块入门 4

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 range sum.

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 sum of all numbers in [l,r][l, r] modulo (c+1)(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.

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

Hint

Subtasks

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

Subtask 2 (60 points): 1≤n≤3×1051 \leq n \leq 3\times 10^5, −231≤ai,c≤231−1-2^{31} \leq a_i, c \leq 2^{31}-1.

For all testdata, 1≤n≤3×1051 \leq n \leq 3\times 10^5 and −231≤ai,c≤231−1-2^{31} \leq a_i, c \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. In particular, the testdata guarantee that c≥0c \geq 0 when opt=1\mathrm{opt}=1.

Translated by QwenWork