#K14566. Count Active Sessions
Count Active Sessions
Count Active Sessions
You are given a list of sessions and a list of query timestamps. Each session is represented by two integers indicating its start time S and end time E. A session is active at a query time T if and only if S ≤ T ≤ E. Mathematically, the number of active sessions at time T can be expressed as:
$$\text{active}(T) = \sum_{i=1}^{n} \mathbf{1}(S_i \le T \le E_i) $$where (\mathbf{1}(\cdot)) is the indicator function.
Your task is to compute, for each query, the number of sessions that are active at that particular timestamp.
Example: For sessions = [(1, 5), (2, 6), (4, 8)] and query time T = 5, the active count is 3 because all three sessions satisfy 1 ≤ 5 ≤ 5, 2 ≤ 5 ≤ 6, and 4 ≤ 5 ≤ 8 respectively.
inputFormat
The input is given via standard input (stdin) with the following format:
- The first line contains an integer (n), the number of sessions.
- Each of the next (n) lines contains two integers (S) and (E), representing the start and end times of a session.
- The next line contains an integer (m), the number of query timestamps.
- Each of the next (m) lines contains a single integer (T), a query timestamp.
outputFormat
Print a single line to standard output (stdout) containing (m) integers separated by a space. Each integer represents the number of active sessions at the corresponding query timestamp.## sample
5
1 5
2 6
4 8
10 12
9 9
3
3
5
9
2 3 1