Gahui and Keywords
Time limit1.5sMemory limit512 MB
Keep a set of notebook keywords, remove the keywords named in each comma-separated post line, and report the remaining count after each post.
- Level
Medium4 of 10
- Topics
- Hash map, String, Implementation, Simulation
- Solved
- No attempts yet
Problem
Gahui runs a blog. To write posts for the blog, Gahui writes keywords down in a notebook.
The keywords written in the notebook so far are all distinct, and there are N of them in total.
When Gahui writes a new post, she writes about at most 10 keywords.
Any of these keywords that was in the notebook is erased from the notebook after Gahui writes the post.
After writing a post on the blog, Gahui wants to know how many keywords are in the notebook. Help Gahui.
Input
The first line gives the number of keywords Gahui wrote in the notebook, N, and the number of posts Gahui wrote on the blog, M, separated by a space.
Lines 2 through N+1 give the N keywords written in the notebook.
Lines N+2 through N+M+1 give the keywords related to the post Gahui wrote, separated by , (commas). Note that they are not separated by spaces.
Output
On line x, print the number of keywords remaining in the notebook after the x-th post is written.
Constraints
- 1 ≤ N ≤ 2×105
- 1 ≤ M ≤ 2×105
- 1 ≤ number of keywords in a post ≤ 10
- 1 ≤ keyword length ≤ 10
- Keywords consist only of lowercase letters and digits.
- Keyword names in the notebook are distinct.
- Keyword names in a post are distinct. However, one keyword may appear in multiple posts.