#K63142. Artem's Time Traveler's List
Artem's Time Traveler's List
Artem's Time Traveler's List
This problem involves implementing a data structure that supports time travel on a list of strings. You need to process a sequence of queries, where each query applies an operation at a given moment in time. The operations are:
- Add: Add an instance of a string at a specified time.
- Remove: Remove an instance of a string at a specified time.
- Count: Count the number of instances of the string at a given time. The count should consider all add (value +1) and remove (value -1) operations with a time less than or equal to the query time.
For a query of type 3, the answer is the net count of the string considering all events up to that time. Formally, if we denote each add as +1 and each remove as -1 and let \(\text{op}(t)\) be the operation at time \(t\), then for a count query at time \(T\) the result is:
\(\displaystyle \sum_{t \le T} \text{op}(t)\)
Implement the handling of these queries so that the program reads input from standard input (stdin) and writes the results of count queries to standard output (stdout).
inputFormat
The input is given via standard input. The first line contains a single integer \(n\) which is the number of queries. Each of the next \(n\) lines contains a query in the format:
query_type time string
where:
query_type
is an integer that is either 1 (add), 2 (remove), or 3 (count).time
is an integer representing the moment in time when the event occurs.string
is a single word representing the string to add, remove, or count.
outputFormat
For each count query (query type 3), output the result on a new line to standard output. The result is the number of instances of the queried string at the specified time.
## sample6
1 1 hello
3 4 hello
1 3 world
3 5 hello
2 2 hello
3 6 hello
1
1
0
</p>