#C5347. Taco Treasure Hunt
Taco Treasure Hunt
Taco Treasure Hunt
You are given the positions of treasures along a one-dimensional line. For each test case, you are provided with n treasure positions and q queries. Each query is specified by two integers l and r and asks you to count the number of treasures whose positions fall within the range \([l, r]\) (inclusive).
To efficiently process the queries, it is recommended to first sort the treasure positions. Then, by using binary search (or appropriate library functions) you can quickly determine the number of treasures in any given range.
Note: The range is defined in the mathematical form as \([l, r]\), where both endpoints are included.
inputFormat
The first line contains an integer T
, the number of test cases.
For each test case, the first line contains two space-separated integers n
and q
, where n
is the number of treasures and q
is the number of queries.
The second line contains n
space-separated integers representing the positions of the treasures.
Then q
lines follow, each containing two space-separated integers l
and r
, representing the inclusive query range \([l, r]\).
outputFormat
For each query in each test case, output the number of treasure positions that lie in the given inclusive range \([l, r]\). The answers for each test case should be printed consecutively, each on a new line.
## sample1
5 3
2 5 7 10 12
1 6
5 10
7 15
2
3
3
</p>