#K80832. Unique Event Date Query
Unique Event Date Query
Unique Event Date Query
In this problem, you are required to implement an event manager that supports two types of operations: Add
and Query
.
When an Add
operation is given with a date in the format YYYYMMDD, the event date is inserted into a set (duplicates are ignored). When a Query
operation is provided with two dates, start_date and end_date, your task is to report the number of unique event dates that fall into the inclusive range \([start\_date,\ end\_date]\).
Note: The operations will be given from standard input (stdin) and the results for each Query
should be output on separate lines to standard output (stdout).
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains a single integer
T
representing the total number of operations. - Each of the next
T
lines contains an operation. Each operation is one of the two formats:Add <date>
— where<date>
is an 8-digit integer in the format YYYYMMDD.Query <start_date> <end_date>
— where<start_date>
and<end_date>
are 8-digit dates. This operation requires you to count all unique event dates in the inclusive range \([start_date, end_date]\).
outputFormat
For each Query
operation, output one integer on a new line representing the count of unique event dates within the specified range.
7
Add 20230101
Add 20230102
Query 20230101 20230103
Add 20230101
Query 20230101 20230101
Add 20230301
Query 20230101 20231231
2
1
3
</p>