#K43992. Unique Days in Task Queries
Unique Days in Task Queries
Unique Days in Task Queries
You are given a sequence of tasks where each task is associated with a day. The day on which task i is completed is given by an integer. You are also provided with multiple queries; each query consists of two integers L and R, representing a range of tasks (using 1-indexing). For each query, your task is to determine the number of unique days on which the tasks in the range [L, R] were completed.
The problem can be mathematically expressed as follows:
[ unique(L, R) = \Big| { a_L, a_{L+1}, \ldots, a_R } \Big| ]
where (|\cdot|) denotes the size of the set.
For example, if task_days = [3, 1, 2, 3, 2, 1] and queries = [(1, 3), (2, 5), (1, 6)], then the output should be: 3 3 3
Read the input from standard input (stdin) and output the answer for each query on a new line in standard output (stdout).
inputFormat
The input is read from standard input (stdin) with the following format:
- The first line contains a single integer (N), the number of tasks.
- The second line contains (N) space-separated integers, where the i-th integer represents the day on which task i was completed.
- The third line contains a single integer (Q), the number of queries.
- Each of the following (Q) lines contains two space-separated integers (L) and (R) (1-indexed), representing a query.
outputFormat
For each query, print a single line with the number of unique days in the range [L, R] of the given task days.## sample
6
3 1 2 3 2 1
3
1 3
2 5
1 6
3
3
3
</p>