#P9912. [COCI 2023/2024 #2] Zatopljenje

[COCI 2023/2024 #2] Zatopljenje

Problem Description

Mr. Malnar has a topographic map that shows the elevation at each position in a certain area. Specifically, there are nn positions arranged in a line, and the ii-th position is hih_i meters above sea level.

Sea level may rise. You are given qq queries. For the ii-th query, you need to answer: if sea level rises by xix_i meters, how many islands will form in the interval [li,ri][l_i, r_i]? An island is defined as a maximal segment in which every position has height greater than xix_i.

The figure above shows the first query of Sample 1 and the second query of Sample 2, respectively. In the left figure, there are two islands [2,2][2,2] and [4,5][4,5] in the interval [2,5][2,5], while in the right figure there are four islands [1,1][1,1], [4,4][4,4], [8,8][8,8], and [10,10][10,10].

Input Format

The first line contains two integers n,qn, q.

The second line contains nn integers h1nh_{1\sim n}, representing the initial elevation of each position.

The next qq lines each contain 33 integers li,ri,xil_i, r_i, x_i, representing one query.

Output Format

Output qq lines. The ii-th line contains one integer, the answer to the ii-th query.

6 3
2 4 2 3 4 1
2 5 2
3 5 3
3 4 4
2
1
0
10 3
5 0 3 4 2 0 1 6 3 5
3 9 1
1 10 3
1 10 2
2
4
3

Hint

Constraints

Subtask\text{Subtask} Score Special Property
11 1010 n,q2000n, q\le 2000
22 2020 li=1,ri=nl_i=1, r_i=n
33 There exists p[1,n]p\in [1,n] such that $h_1\ge h_2\ge \cdots \ge h_p\le h_{p+1}\le \cdots \le h_n$
44 6060 None

For all testdata, 1n,q2×1051\le n, q\le 2\times 10^5, 0hi,xi1090\le h_i, x_i\le 10^9, 1lirin1\le l_i\le r_i\le n.

Translated by ChatGPT 5