#P7252. [JSOI2011] 棒棒糖
[JSOI2011] 棒棒糖
Description
Lollipops are also sold in Coffee’s world. Coffee bought connected lollipops. These lollipops are wrapped in small plastic bags and arranged in a line, and the plastic bags of two adjacent lollipops are attached to each other. For convenience, we number the lollipops from left to right as .
Each lollipop has a flavor. The flavor of the -th lollipop is . Two lollipops have the same flavor if and only if . Coffee’s way of judging the overall flavor of lollipops is somewhat strange. If among these lollipops, there is a flavor whose count is strictly greater than half of the total, then Coffee thinks these lollipops are mainly of flavor . Coffee knows that if such a exists, it must be unique. If does not exist, Coffee thinks these lollipops are mixed flavor.
Coffee is not willing to eat the lollipops for now, and is thinking about some interesting questions. Consider a contiguous subsequence of the lollipop sequence, including lollipops and . What is the overall flavor of these lollipops?
Coffee has many such questions, in total. The -th question asks for the overall flavor of the lollipop subsequence . Please help solve them.
Input Format
The first line contains two integers separated by spaces, representing .
The next lines each contain one integer, representing .
The next lines each contain two integers, representing .
Output Format
Output lines, each containing one integer, representing the overall flavor for each query. If the overall flavor is mixed flavor, output .
5 3
1
2
2
1
1
1 5
2 5
2 4
1
0
2
Hint
Sample Explanation 1
In the first query, flavor appears times, which is more than half of the total, so the overall flavor is .
In the second query, no flavor appears more than half of the total, so it is mixed flavor.
In the third query, flavor appears times, which is more than half of the total, so the overall flavor is .
Constraints
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号