#K80787. Distinct Elements Count with Queries

    ID: 35608 Type: Default 1000ms 256MiB

Distinct Elements Count with Queries

Distinct Elements Count with Queries

Given an array of n integers and q queries, your task is to count, for each query, the number of distinct elements in the array that are less than or equal to the query value.

The distinct set of numbers is defined as the set of unique integers in the given array. Once you remove duplicates and sort the array, for a query value \( x \), you need to compute the number of elements \( a_i \) such that \( a_i \le x \). Formally, if \( S = \{a_1, a_2, \ldots, a_k\} \) is the sorted set of distinct elements, then for each query \( x \) output:

\[ \text{result}(x) = |\{ s \in S : s \le x \}| \]

All input is read from STDIN and output should be printed to STDOUT.

inputFormat

The input consists of three lines:

  1. The first line contains two integers \( n \) and \( q \) denoting the number of integers in the array and the number of queries, respectively.
  2. The second line contains \( n \) space-separated integers representing the array.
  3. The third line contains \( q \) space-separated integers representing the query values.

You can assume that \( 1 \le n, q \le 10^5 \) and the integers are within a reasonable range to fit in standard integer types.

outputFormat

For each query, output a single integer on a new line that indicates the number of distinct elements in the array that are less than or equal to the query value.

## sample
6 3
1 5 2 2 3 5
2 4 5
2

3 4

</p>