#P3616. Continuous Visible Segments
Continuous Visible Segments
Continuous Visible Segments
This problem is set in a mountain range in Fu Jin Forest Park. The mountain range is composed of N giant stones lined up consecutively, numbered from 1 to N. Each stone has an altitude, and the entire range is located in a basin where water may accumulate. The water level is given as an altitude w, and any stone with an altitude strictly less than w will be hidden underwater. Stones whose altitude is equal to w are considered visible.
Due to crustal movements, the altitude of a stone may be updated at any time. There are two types of operations:
- Update Operation: Update the altitude of a given stone.
- Query Operation: Given a water level w, determine the number of continuous segments of stones that are visible (i.e. stones with altitude ≥ w form a continuous segment).
For example, consider the altitudes [2, 4, 3, 5, 1] and a water level w = 3. Stones with altitudes 4, 3, and 5 are visible consecutively (because 2 is hidden and 1 is hidden), forming one continuous segment.
The formulas involved are as follows:
Visible condition for a stone with altitude a: $$a \ge w.$$
inputFormat
The first line contains two integers N and Q (1 ≤ N, Q ≤ 105), representing the number of stones and the number of operations, respectively.
The second line contains N integers, where the i-th integer represents the altitude of the i-th stone.
The following Q lines each represent an operation. An operation is either:
1 x h
— Update the altitude of stone x (1-indexed) to h.2 w
— Query the number of continuous visible segments when the water level is w.
Note: For a query operation, a stone is visible if its altitude is greater than or equal to the water level w (i.e., meeting the condition $$a_i \ge w$$).
outputFormat
For each query operation (operations of type 2
), output an integer on a new line representing the number of continuous segments of visible stones.
sample
5 5
2 4 3 5 1
2 3
1 5 6
2 3
1 3 2
2 3
1
1
2
</p>