#K61277. Unique Product Count in Time Range
Unique Product Count in Time Range
Unique Product Count in Time Range
You are given a list of sales transactions. Each transaction contains a product identifier (a string) and a timestamp (an integer). A time range is also provided, specified as \(\left[t_{start}, t_{end}\right]\), where both endpoints are inclusive. Your task is to determine, for each test case, the number of distinct product IDs that have occurred within the given time range.
Explanation: For a test case, consider every transaction \((\text{productID}, timestamp)\). Count a product if its timestamp \(t\) satisfies \(t_{start} \le t \le t_{end}\). The answer for the test case is the number of unique product IDs that satisfy this condition.
Note: Use \(\LaTeX\) format for any formulas. For example, the time range condition is given by \(t_{start} \le t \le t_{end}\).
inputFormat
The input is provided via standard input (stdin) and follows this format:
T N productID timestamp ... (repeated N times) t_start t_end ... (repeated for each test case)
Where:
T
is the number of test cases.- For each test case,
N
is the number of transactions. - Each of the next N lines contains a product ID (string) and a timestamp (integer) separated by a space.
- The next line contains two integers representing
t_start
andt_end
, the inclusive time range.
outputFormat
For each test case, output a single integer on a new line representing the number of distinct product IDs whose transaction timestamps lie within the inclusive time range \(t_{start} \le t \le t_{end}\).
## sample2
5
productA 1
productB 2
productC 3
productA 5
productB 8
1 5
4
item1 10
item2 20
item3 30
item1 40
15 35
3
2
</p>