#4515. HDU5919 Sequence II
HDU5919 Sequence II
Problem Description
Mr. Frog has an integer sequence of length ,which can be denoted as . There are queries.
In the -th query, you are given two integers and . Consider the subsequence $ a_{l_i}, a_{l_{i+1}}, a_{l_{i+2}}, \cdots, a_{r_i} $.
We can denote the positions (the positions according to the original sequence) where an integer appears first in this subsequence as (in ascending order, i.e., $ p_{1}^{(i)} < p_{2}^{(i)} < \cdots < p_{k_i}^{(i)} $).
Note that is the number of different integers in this subsequence. You should output $ p_{\left \lceil \frac{k_i}{2} \right \rceil}^{(i)} $ for the -th query.
Input
In the first line of input, there is an integer () denoting the number of test cases.
Each test case starts with two integers () and (). There are integers in the next line, which indicate the integers in the sequence (i.e., , ).
There are two integers and in the following lines.
However, Mr. Frog thought that this problem was too young too simple so he became angry. He modified each query to (, ). As a result, the problem became more exciting.
We can denote the answers as . Note that for each test case .
You can get the correct input from what you read (we denote them as ) by the following formula:
$[
l_i = \min { (l_i' + ans_{i-1}) \mod n + 1, (r_i' + ans_{i-1}) \mod n + 1 }
]$
$[
r_i = \max { (l_i' + ans_{i-1}) \mod n + 1, (r_i' + ans_{i-1}) \mod n + 1 }
]$
Output
You should output one single line for each test case.
For each test case, output one line “Case #x: ”, where is the case number (starting from 1) and is the answer.
Sample Input
2
5 2
3 3 1 5 4
2 2
4 4
5 2
2 5 2 1 2
2 3
2 4
Sample Output
Case #1: 3 3
Case #2: 3 1