| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 59 | 31 | 25 | 51.020% |
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 $n$ numbers $h_1, h_2, \dots , h_n,ドル where the $i$-th number represents relief height at the $i$-th point. Mr. Malnar has $q$ queries, where the $i$-th query is as following: How many islands would there be between the $l_i$-th and $r_i$-th point if the sea level rose by $x_i$ 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 $[2, 2]$ and $[4, 5]$.
The right islands correspond to intervals $[1, 1],ドル $[4, 4],ドル $[8, 8]$ and $[10, 10]$.
An island is defined as the maximal interval where every $h_i$ 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 0ドル$ meters.
The first line contains integers $n$ and $q$ (1ドル ≤ n, q ≤ 2 \cdot 10^5$), the length of the sequence and the number of queries.
The second line contains $n$ integers $h_1, h_2, \dots , h_n$ (0ドル ≤ h_i ≤ 10^9$) that describe the relief of the coast.
In each of the next $q$ lines there are three integers $l_i,ドル $r_i$ and $x_i$ (1ドル ≤ l_i ≤ r_i ≤ n,ドル 0ドル ≤ x_i ≤ 10^9$) that describe the $i$-th query.
In the $i$-th of the $q$ lines print the answer to the $i$-th query. Each of the queries is independent of the others.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 10 | $n, q ≤ 2 \cdot 10^3$ |
| 2 | 20 | $l_i = 1,ドル $r_i = n$ for all $i = 1, 2, \dots , q$ |
| 3 | 20 | There exists an integer $p$ (1ドル ≤ p ≤ n$) such that the following holds: $h_1 ≥ h_2 ≥ \cdots ≥ h_p$ and $h_p ≤ h_{p+1} ≤ \cdots ≤ h_n$ |
| 4 | 60 | No additional constraints. |
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
Clarification of the first example:
The first query is shown in the left image in the task description, islands correspond to intervals $[2, 2]$ and $[4, 5]$. In the second query island corresponds to interval $[5, 5]$. 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 $[3, 5]$ and $[8, 9]$. In the second query (shown in the right image in the task description) islands correspond to intervals $[1, 1],ドル $[4, 4],ドル $[8, 8]$ and $[10, 10],ドル while in the third query islands correspond to intervals $[1, 1],ドル $[3, 4]$ and $[8, 10]$.