luogu#P8010. 「Wdsr-3」令人感伤的红雨

「Wdsr-3」令人感伤的红雨

Background

Shizuha Aki is the goddess who manages falling leaves in autumn. When autumn is about to end, due to her power, the mountains will turn completely fiery red. At the same time, turning red leaves into fallen leaves is also part of her job.

Minoriko Aki is the goddess who manages harvest in autumn. Opposite to Shizuha Aki’s duty, she is in charge of the ripening of autumn fruits and the harvesting of autumn crops.

In an autumn woven with happiness and sorrow, how can one not feel sentimental?

Problem Description

Minoriko Aki and Shizuha Aki are deities in charge of autumn, so they control the harvest of the fields. Specifically, there are nn fields arranged in order, and the harvest level of the ii-th field is aia_i. The Aki sisters will use this to determine how good the year’s harvest is.

After considering various factors, the Aki sisters determined that harvesting fields ll through rr yields a total crop amount Ω(l,r)\Omega(l,r). It is defined as follows:

$$\begin{aligned} \Alpha(l,r)&=\max_{i=l}^r\{i\times[a_i=\max_{j=l}^r\{a_j\}]\}\cr \Beta(l,r)&=\max_{i=l}^r\{\min_{j=1}^i\{\Alpha(j,i)\}\}-\min_{i=l}^r\{\max_{j=1}^i\{\Alpha(j,i)\}\}\cr \Omega(l,r)&=\min_{i=l}^r\{\min_{j=i}^r\{|\Beta(i,j)|\}\} \end{aligned}$$

There is an explanation of the related symbols in the Hint section.


Due to certain factors, the harvest levels of the fields will change. Therefore, the Aki sisters will perform qq operations on aa:

  1. In the form 1 x y\colorbox{f0f0f0}{\verb!1 x y!}, meaning to add yy to a1,a2,a3,,axa_1,a_{2},a_{3},\cdots ,a_x respectively.
  2. In the form 2 l r\colorbox{f0f0f0}{\verb!2 l r!}, meaning to query the value of Ω(l,r)\Omega(l,r).

Input Format

  • The first line contains two positive integers n,qn,q, representing the total number of fields and the number of operations.
  • The next line contains nn integers, representing the harvest level of each field.
  • The next qq lines: the first number opop indicates the type of the operation.
    • If op=1op=1, then two integers x,yx,y follow, with the meaning as described.
    • If op=2op=2, then two positive integers l,rl,r follow, with the meaning as described.

Output Format

  • Output several lines. For each operation 22, output the corresponding result.
6 3
1 1 4 5 1 4
2 3 5
1 2 5
2 3 5
0
1
10 6
1 3 5 7 8 12 14 15 17 18
2 5 9
1 3 10
2 4 5
1 1 10
2 4 6
2 1 10
0
1
3
0

Hint

Sample 33 can be found in the attached files $\textbf{\textit{sequence3.in}}/\textbf{\textit{sequence3.ans}}$.

Constraints and Conventions

$$\def\arraystretch{1.5} \begin{array}{|c|c|c|c|}\hline \textbf{Subtask} & \bm{n,q\le} & \textbf{Special Property} & \textbf{Score}\cr\hline 1 & 100 & - & 10\cr\hline 2 & 5\times 10^3 & - &15\cr\hline 3 & 10^5 & \text{A} &10\cr\hline 4 & 10^5 & \text{B} &5\cr\hline 5 & 10^5 & - &30\cr\hline 6 & 6\times 10^6 & - & 30\cr\hline \end{array}$$

Special Property A\textbf{A}: It is guaranteed that for any i[1,n1]i\in[1,n-1], we have ai<ai+1a_i<a_{i+1}.
Special Property B\textbf{B}: It is guaranteed that there is no operation 11.

For all testdata, it is guaranteed that 1n,q6×1061 \leq n,q \leq 6\times10^6, ai,yi[0,109]a_i,y_i\in[0,10^9], 1xin1\le x_i\le n, and 1lirin1\le l_i\le r_i \le n.

Symbol Explanation

  • [P][P] is the Iverson bracket, where PP is a condition. If PP is true, then the value of the expression is 11; otherwise it is 00. That is,
$$[P]=\begin{cases}1 & \text{$P$ is true}\cr 0 & \text{$P$ is false}\end{cases}$$
  • mini=lr{P}\min\limits_{i=l}^r\{P\} denotes the minimum value of the expression PP when ii takes l,l+1,l+2,,rl,l+1,l+2,\cdots,r. Similarly, maxi=lr{P}\max\limits_{i=l}^r\{P\} is defined.

Additional Hint

The input and output size of this problem is large, so please pay attention to the impact of constant factors.

Translated by ChatGPT 5