
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 the 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

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
The right islands correspond to intervals
An island is defined as the maximal interval where every
Input Specification
The first line contains integers
The second line contains
In each of the next
Output Specification
In the
Constraints
Subtask | Points | Constraints |
---|---|---|
1 | 10 | |
2 | 20 | |
3 | 20 | There exists an integer |
4 | 60 | No additional constraints. |
Sample Input 1
6 3
2 4 2 3 4 1
2 5 2
3 5 3
3 4 4
Sample Output 1
2
1
0
Explanation for Sample 1
The first query is shown in the left image in the task description, the islands correspond to the intervals
Sample Input 2
10 3
5 0 3 4 2 0 1 6 3 5
3 9 1
1 10 3
1 10 2
Sample Output 2
2
4
3
Explanation for Sample 2
In the first query, the islands correspond to the intervals
Comments