[POI2014] KUR-Couriers

题意翻译

给一个长度为 $n$ 的正整数序列 $a$。共有 $m$ 组询问,每次询问一个区间 $[l,r]$ ,是否存在一个数在 $[l,r]$ 中出现的次数严格大于一半。如果存在,输出这个数,否则输出 $0$。 $1 \leq n,m \leq 5 \times 10^5$,$1 \leq a_i \leq n$。

题目描述

Byteasar works for the BAJ company, which sells computer games. The BAJ company cooperates with many courier companies that deliver the games sold by the BAJ company to its customers. Byteasar is inspecting the cooperation of the BAJ company with the couriers. He has a log of successive packages with the courier company that made the delivery specified for each package. He wants to make sure that no courier company had an unfair advantage over the others. If a given courier company delivered more than half of all packages sent in some period of time, we say that it dominated in that period. Byteasar wants to find out which courier companies dominated in certain periods of time, if any. Help Byteasar out! Write a program that determines a dominating courier company or that there was none. 给一个数列,每次询问一个区间内有没有一个数出现次数超过一半

输入输出格式

输入格式


The first line of the standard input contains two integers, ![](http://main.edu.pl/images/OI21/kur-en-tex.1.png) and ![](http://main.edu.pl/images/OI21/kur-en-tex.2.png) (![](http://main.edu.pl/images/OI21/kur-en-tex.3.png)), separated by a single space, that are the number of packages shipped by the BAJ company and the number of time periods for which the dominating courier is to be determined, respectively. The courier companies are numbered from ![](http://main.edu.pl/images/OI21/kur-en-tex.4.png) to (at most) ![](http://main.edu.pl/images/OI21/kur-en-tex.5.png). The second line of input contains ![](http://main.edu.pl/images/OI21/kur-en-tex.6.png) integers, ![](http://main.edu.pl/images/OI21/kur-en-tex.7.png) (![](http://main.edu.pl/images/OI21/kur-en-tex.8.png)), separated by single spaces; ![](http://main.edu.pl/images/OI21/kur-en-tex.9.png) is the number of the courier company that delivered the ![](http://main.edu.pl/images/OI21/kur-en-tex.10.png)-th package (in shipment chronology). The ![](http://main.edu.pl/images/OI21/kur-en-tex.11.png) lines that follow specify the time period queries, one per line. Each query is specified by two integers, ![](http://main.edu.pl/images/OI21/kur-en-tex.12.png) and ![](http://main.edu.pl/images/OI21/kur-en-tex.13.png) (![](http://main.edu.pl/images/OI21/kur-en-tex.14.png)), separated by a single space. These mean that the courier company dominating in the period between the shipments of the ![](http://main.edu.pl/images/OI21/kur-en-tex.15.png)-th and the ![](http://main.edu.pl/images/OI21/kur-en-tex.16.png)-th package, including those, is to be determined. In tests worth ![](http://main.edu.pl/images/OI21/kur-en-tex.17.png) of total score, the condition ![](http://main.edu.pl/images/OI21/kur-en-tex.18.png) holds, and in tests worth ![](http://main.edu.pl/images/OI21/kur-en-tex.19.png) of total score ![](http://main.edu.pl/images/OI21/kur-en-tex.20.png).

输出格式


The answers to successive queries should be printed to the standard output, one per line. (Thus a total of ![](http://main.edu.pl/images/OI21/kur-en-tex.21.png) lines should be printed.) Each line should hold a single integer: the number of the courier company that dominated in the corresponding time period, or ![](http://main.edu.pl/images/OI21/kur-en-tex.22.png) if there was no such company.

输入输出样例

输入样例 #1

7 5
1 1 3 2 3 4 3
1 3
1 4
3 7
1 7
6 6

输出样例 #1

1
0
3
0
4