Mock CCC '22 1 S4 - Berkeley Math Tournament Statistics

View as PDF

Submit solution


Points: 20 (partial)
Time limit: 0.25s
Memory limit: 32M

Problem type

Kaity is collecting statistics for the latest iteration of the Berkeley Math Tournament. In the last tournament, she had N students numbered from 1 to N participating. Each student received a score that was a positive integer number of points.

One day, Sylvia, her archnemesis, wanted to collect statistics about how well students did in the tournament. Sylvia has Q questions. Each question takes the form: Among all students from Li to Ri, what was the most frequent score among the given students?

Kaity is a nice person and wants the students to look as good as possible, so if multiple scores are tied for most frequent, she will tell Sylvia the largest mode.

Sylvia is impatient, so please answer her questions as quickly as possible!

Constraints

1N,Q105

1siN

1LiRiN

In tests worth 1 mark, N,Q103.

In tests worth an additional 2 marks, N,Q104.

In tests worth an additional 3 marks, N,Q2104.

In tests worth an additional 4 marks, N,Q5104.

Input Specification

The first line contains two integers, N and Q.

The next line contains N integers, the scores si of the students from 1 to N in order.

The next Q lines contain two integers each, Li and Ri, indicating the set of students Sylvia is asking about.

Output Specification

Output Q lines. On line i, output the answer to Sylvia's ith question.

Sample Input

Copy
5 3
2 1 2 1 1
1 2
1 4
1 5

Sample Output

Copy
2
2
1

Comments


  • 1
    Puddle  commented on April 26, 2022, 12:44 p.m. edited

    Is it even possible to solve this problem in Python 3 or Pypy3? (not asking for the solution, but all the correct answers have been in C++)


    • 1
      xiaowuc1  commented on April 26, 2022, 6:10 p.m.

      The only languages where this problem is expected to be solvable are C and C++.