#P114. [TFXOI Round 1] 创世纪

[TFXOI Round 1] 创世纪

Source

This problem is proposed by . All rights reserved.

Problem Source: https://www.luogu.com.cn/problem/T565382

Problem Background

Created in silence, born from chaos, blooming in darkness.

Problem Description

After the "God" created "history," He felt that there should be something meaningful in this infinitely long "history." Thus, He decided to create the "world."

This "world" consists of nn "lands" with heights aia_i.
An interval [l,r][l,r] is called a "peak" if it satisfies:

$$r-l+1\ge3,\quad \exists k\in (l,r),\quad a_l<a_{l+1}<\ldots<a_k \gt\ldots\gt a_{r-1}\gt a_r$$

Similarly, an interval [l,r][l,r] is called a "valley" if it satisfies:

$$r-l+1\ge3,\quad \exists k\in (l,r),\quad a_l>a_{l+1}>\ldots>a_k<\ldots<a_{r-1}<a_r$$

As "history" progresses, mm events will occur on the "world," each being one of the following 4 types:

  • Query: Given l,rl,r, tell the "God" the number of "peak" and "valley" subintervals in [l,r][l,r].
  • Land Creation: Given l,r,vl,r,v, perform i[l,r],aiai+v\forall i\in [l,r], a_i \gets a_i + v.
  • Erosion: Given l,r,vl,r,v, perform i[l,r],aiai×v\forall i\in [l,r], a_i \gets a_i \times v.
  • Reshaping: Given l,r,vl,r,v, perform i[l,r],aiv\forall i\in [l,r], a_i \gets v.

Special Note: If any operation causes any aia_i to fall outside [109,109][-10^9, 10^9], that operation is ignored.

As the "God's" agent witnessing the creation, can you answer all of the "God's" queries?

Like you, the "God" finds precision issues with real numbers uninteresting, so if xy105\lvert x-y\rvert\le 10^{-5}, then x=yx=y is considered true. Note that this = is not transitive.

Input Format

The first line contains two integers n,mn,m.
The second line contains nn real numbers, representing the heights aia_i of the ii-th "land."
The next mm lines each start with an integer opop:

  • If op=0op=0, this is a query, followed by two integers l,rl,r, representing the query interval.
  • If op=1op=1, this is a land creation, followed by two integers l,rl,r and one real number vv, representing the interval and parameter for the operation.
  • If op=2op=2, this is an erosion, followed by two integers l,rl,r and one real number vv, representing the interval and parameter for the operation.
  • If op=3op=3, this is a reshaping, followed by two integers l,rl,r and one real number vv, representing the interval and parameter for the operation.

Output Format

Several lines, where the ii-th line contains two integers, representing the number of "peaks" and "valleys" in the interval for the ii-th query.

Samples

5 5
2 3 1 3 2
0 1 4
2 3 4 0.5
1 2 3 2
3 5 5 1.5
0 1 5
1 1
2 0
5 5
4.6 -0.6 3.6 -1.9 -1.5
2 2 5 2.8
3 2 3 1.0
0 3 5
1 1 1 4.4
0 2 4
0 1
0 0

Sample 1 Explanation

  • Initial "world": 2,3,1,3,22, 3, 1, 3, 2.
  • First query [1,4][1,4]:
    • "Peaks": {2,3,1}\{2,3,1\}, 1.
    • "Valleys": {3,1,3}\{3,1,3\}, 1.
  • Second erosion [3,4][3,4], the "world" becomes: 2,3,0.5,1.5,22, 3, 0.5, 1.5, 2.
  • Third land creation [2,3][2,3], the "world" becomes: 2,5,2.5,1.5,22, 5, 2.5, 1.5, 2.
  • Fourth reshaping [5,5][5,5], the "world" becomes: 2,5,2.5,1.5,1.52, 5, 2.5, 1.5, 1.5.
  • Fifth query [1,5][1,5]:
    • "Peaks": {2,5,2.5},{2,5,2.5,1.5}\{2,5,2.5\}, \{2,5,2.5,1.5\}, 2.
    • No "valleys", 0.

Sample 2 Explanation

"Lands" with negative heights also exist.

Data Range

This problem uses bundled tests.

For all data:

  • 3n5×1053\le n\le5\times10^5.
  • 1m1051\le m\le10^5.
  • 109ai109-10^9\le a_i\le10^9.
  • 0op30\le op\le3.
  • 1lrn1\le l\le r\le n.
  • 109v109-10^9\le v\le 10^9.

Due to precision issues, it is recommended to use long double for calculations to avoid incorrect answers.

It is guaranteed that no two originally distinct adjacent numbers will become equal due to precision errors after any "erosion" operation. Thus, you do not need to handle equality caused by precision errors after multiple operations.

Subtask No. nn mm Special Properties Time Limit Points
11 20\le20 1000\le1000 None 1s1\text{s} 1010
22 200\le200
33 2000\le2000
44 105\le10^5 105\le10^5 A 2020
55 B 2s2\text{s}
66 5×105\le5\times10^5 None 3030
  • Special Property A: All lili+1l_i\le l_{i+1} and riri+1r_i\le r_{i+1}.
  • Special Property B: All ai,v>0a_i,v>0 and op{0,1}op\in\{0,1\}.