Zatopljenje
문제
It’s winter, it has never been colder, and Mr. Malnar is looking at his photos from his last cruise on the Adriatic and recalls unforgettable moments. The TV is on in the background, broadcasting news about the latest proposals for measures to slow down sea level rise. Looking at his photos of the coast, Mr. Malnar asks himself what the photos would have looked like if sea level had risen a certain amount. There are so many pictures, and even more questions, so Mr. Malnar asks for your help.
We imagine the coast as a sequence of numbers , where the -th number represents relief height at the -th point. Mr. Malnar has queries, where the -th query is as following: How many islands would there be between the -th and -th point if the sea level rose by meters?
The left image shows the first query of the first sample test case, and the right image shows the second query of the second sample test case.
The left islands correspond to intervals and .
The right islands correspond to intervals , , and .
An island is defined as the maximal interval where every is strictly greater than the sea level. A maximal interval is one that cannot be extended in either direction while keeping the mentioned condition true. Initially, the sea level is at meters.
입력
The first line contains integers and (1 ≤ n, q ≤ 2 \cdot 10^5), the length of the sequence and the number of queries.
The second line contains integers (0 ≤ h_i ≤ 10^9) that describe the relief of the coast.
In each of the next lines there are three integers , and (1 ≤ l_i ≤ r_i ≤ n, 0 ≤ x_i ≤ 10^9) that describe the -th query.
출력
In the -th of the lines print the answer to the -th query. Each of the queries is independent of the others.
힌트
Clarification of the first example:
The first query is shown in the left image in the task description, islands correspond to intervals and . In the second query island corresponds to interval . In the third query there are no islands because everything is under water.
Clarification of the second example: In the first query islands correspond to intervals and . In the second query (shown in the right image in the task description) islands correspond to intervals , , and , while in the third query islands correspond to intervals , and .
예제
예제 1
6 3 2 4 2 3 4 1 2 5 2 3 5 3 3 4 4
2 1 0
예제 2
10 3 5 0 3 4 2 0 1 6 3 5 3 9 1 1 10 3 1 10 2
2 4 3