#C11153. Query on Distinct Integers
Query on Distinct Integers
Query on Distinct Integers
You are given a sequence of M distinct integers and need to answer Q queries. Each query consists of two integers, T and X, where T represents the query type:
- Type 1: Count the elements in the sequence that are less than X. Mathematically, compute \( |\{a \in A : a < X\}| \).
- Type 2: Count the elements in the sequence that are greater than X. Mathematically, compute \( |\{a \in A : a > X\}| \).
- Type 3: Count the elements equal to X. Mathematically, compute \( |\{a \in A : a = X\}| \).
Your task is to process all queries and output the corresponding results.
inputFormat
The input is given in the following format:
M A[0] A[1] ... A[M-1] Q T1 X1 T2 X2 ... TQ XQ
Where:
- M is the number of elements in the array.
- The second line contains M distinct integers separated by spaces.
- Q is the number of queries.
- Each of the next Q lines contains two integers T and X representing a query.
Note: Input is read from standard input (stdin).
outputFormat
For each query, output a single integer on a new line which is the answer for that query. The output should be printed to standard output (stdout).
## sample6
3 1 4 2 7 5
4
1 4
2 3
3 5
1 2
3
3
1
1
</p>