#C10977. Counting Players in Rating Ranges

    ID: 40241 Type: Default 1000ms 256MiB

Counting Players in Rating Ranges

Counting Players in Rating Ranges

You are given a list of player ratings and a series of queries. For each query, determine how many players have ratings that fall within the given inclusive range.

More specifically, for each query with limits \(a\) and \(b\), you need to count the number of elements \(r\) in the list such that \(a \le r \le b\). The problem can be efficiently solved by first sorting the ratings and then using binary search to find the count of ratings within each range.

Input Format: \(n\) is the number of players. The next \(n\) space-separated integers denote the player ratings. An integer \(q\) follows, indicating the number of queries. The next \(q\) lines each contain two integers representing the lower and upper bounds of a query.

Hint: Utilize binary search techniques, such as lower bound and upper bound, to efficiently determine the count for each query.

inputFormat

The first line contains an integer (n), the number of players.\nThe second line contains (n) space-separated integers representing the player ratings.\nThe third line contains an integer (q), the number of queries.\nEach of the next (q) lines contains two integers (a) and (b), representing the inclusive range for the query.

outputFormat

For each query, output a single line containing an integer, which is the count of players whose ratings lie in the inclusive range ([a, b]).## sample

5
100 200 300 400 500
3
100 300
200 400
300 500
3

3 3

</p>