QOJ.ac

QOJ

Time Limit: 1.25 s Memory Limit: 128 MB Total points: 100

#11294. Couriers

統計

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.

Input Format

The first line of the standard input contains two integers, $n$ and $m$ ($1 ≤ n,m ≤ 500\,000$), 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 $1$ to (at most) $n$.

The second line of input contains $n$ integers, $p_{1},p_{2},…,p_{n}$ ($1 ≤ p_{i} ≤ n$), separated by single spaces; $p_{i}$ is the number of the courier company that delivered the $i$-th package (in shipment chronology).

The $m$ lines that follow specify the time period queries, one per line. Each query is specified by two integers, $a$ and $b$ ($1 ≤ a ≤ b ≤ n$), separated by a single space. These mean that the courier company dominating in the period between the shipments of the $a$-th and the $b$-th package, including those, is to be determined.

Output Format

The answers to successive queries should be printed to the standard output, one per line. (Thus a total of m 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 0 if there was no such company.

Example

Input

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

Output

1
0
3
0
4
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.