#P8037. [COCI 2015/2016 #7] Prokletnik
[COCI 2015/2016 #7] Prokletnik
Problem Description
A magic sequence is defined as a sequence in which the values of all elements are between the first element and the last element (inclusive).
Now you are given an array with elements. There are queries . For each query, find the length of the longest magic subarray whose indices in are within .
Input Format
The first line contains an integer .
The second line contains integers .
The third line contains an integer .
The next lines each contain two integers .
Output Format
Output lines. Each line contains the answer to one query.
5
5 4 3 3 2
3
1 2
1 1
2 4
2
1
3
6
6 6 5 1 6 2
3
4 5
4 6
1 4
2
2
4
Hint
【Constraints and Notes】
- For of the testdata, .
- For of the testdata, , , .
【Hints and Explanation】
This problem is translated from COCI 2015-2016 #7 Task 6 Prokletnik.
The score setting of this problem follows the original COCI problem, with a full score of .
Translated by ChatGPT 5