luogu#P5211. [ZJOI2017] 字符串

[ZJOI2017] 字符串

Background

Pig Xiaoxia has recently been studying string-related theory, and now he has encountered the following problem.

Problem Description

Maintain a dynamic string s1..ns_{1..n}, whose alphabet is all integers with x109|x| \leq 10 ^ 9. You need to support two operations:

  1. Input l,r,dl, r, d. For all lirl \leq i \leq r, modify sis_i to si+ds_i + d. Note that dd may be negative.

  2. Input l,rl, r. Output the starting position of the lexicographically smallest suffix of the substring sl..rs_{l..r}. That is, if the smallest suffix is sp..rs_{p..r} (lprl \leq p \leq r), output pp.

Input Format

The first line contains two non-negative integers n,qn, q.

The next line contains nn positive integers, representing the initial string.

The next qq lines each describe an operation in the form 1 l r d1\ l\ r\ d or 2 l r2\ l\ r, corresponding to the two operations above.

Output Format

For each query operation, output the answer in order.

5 5
3 2 1 4 3
2 1 5
1 2 4 2
2 1 5
1 2 5 1
2 1 5

3
5
1

Hint

Test Point ID nn mm Other Constraints
11 300\leq 300 None
22 2×104\leq 2 \times 10^4 2×104\leq 2 \times 10^4
33 2×105\leq 2 \times 10^5
44 2×105\leq 2 \times 10^5 3×104\leq 3 \times 10^4 Only the second type of operation
55
66 testdata generated randomly
77
88 None
99
1010

Constraints: For 100%100\% of the data, 1lrn1 \leq l \leq r \leq n, d103|d| \leq 10 ^ 3, and si108|s_i| \leq 10 ^ 8.

Note: In test points 66 and 77, during random generation, sis_i is chosen randomly from {0,1}\{0, 1\}, and dd is chosen randomly from {1,1}\{-1, 1\}. The operation type and the operation interval are both selected uniformly at random.

Translated by ChatGPT 5