#K75897. Range Log Queries
Range Log Queries
Range Log Queries
You are given a list of log timestamps and a set of queries. Each query specifies a range \([l, r]\) and your task is to determine the count of timestamps that fall within this range, inclusive.
In other words, if you are given an array of integers \(A = [a_1, a_2, \ldots, a_n]\) representing the timestamps, and a query \((l, r)\), you should count how many elements \(a_i\) satisfy the inequality:
[ l \leq a_i \leq r ]
Your solution should efficiently handle the queries. You may preprocess the array if necessary (for example, sorting it) so that each query can be answered quickly using techniques such as binary search.
Example:
Input: 5 1 2 3 4 5 3 1 3 2 4 1 5</p>Output: 3 3 5
inputFormat
The input is read from stdin and has the following format:
- The first line contains a single integer \(n\) indicating the number of log timestamps.
- The second line contains \(n\) space-separated integers representing the timestamps.
- The third line contains a single integer \(q\) representing the number of queries.
- The next \(q\) lines each contain two space-separated integers \(l\) and \(r\) representing a query.
outputFormat
For each query, output the number of timestamps that lie within the range \([l, r]\), each on a new line, written to stdout.
## sample5
1 2 3 4 5
3
1 3
2 4
1 5
3
3
5
</p>