#P7252. [JSOI2011] 棒棒糖

[JSOI2011] 棒棒糖

Description

Lollipops are also sold in Coffee’s world. Coffee bought nn connected lollipops. These nn 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 1n1\cdots n.

Each lollipop has a flavor. The flavor of the ii-th lollipop is cic_i. Two lollipops i,ji,j have the same flavor if and only if ci=cjc_i=c_j. Coffee’s way of judging the overall flavor of mm lollipops is somewhat strange. If among these mm lollipops, there is a flavor c0c_0 whose count is strictly greater than half of the total, then Coffee thinks these mm lollipops are mainly of flavor c0c_0. Coffee knows that if such a c0c_0 exists, it must be unique. If c0c_0 does not exist, Coffee thinks these mm 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 st(1stn)s\cdots t(1\leq s\leq t\leq n) of the lollipop sequence, including lollipops ss and tt. What is the overall flavor of these ts+1t-s+1 lollipops?

Coffee has many such questions, mm in total. The ii-th question asks for the overall flavor of the lollipop subsequence sitis_i\cdots t_i. Please help solve them.

Input Format

The first line contains two integers separated by spaces, representing n,mn,m.

The next nn lines each contain one integer, representing cic_i.

The next mm lines each contain two integers, representing si,tis_i,t_i.

Output Format

Output mm lines, each containing one integer, representing the overall flavor for each query. If the overall flavor is mixed flavor, output 00.

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 11 appears 33 times, which is more than half of the total, so the overall flavor is 11.

In the second query, no flavor appears more than half of the total, so it is mixed flavor.

In the third query, flavor 22 appears 22 times, which is more than half of the total, so the overall flavor is 22.

Constraints

For 100%100\% of the testdata, 1n,m,ci5×1041\leq n,m,c_i\leq 5\times 10^4.

Translated by ChatGPT 5