Multi-Item Preference Survey (Large)
InterviewTime limit3sMemory limit512 MB
Given n students' subject, fruit, and color choices, each query asks how many students match its pattern, where '-' matches any value.
- Level
Easy3 of 10
- Topics
- Hash map, Implementation
- Solved
- No attempts yet
Problem
students were surveyed about their preferences as follows. Each student must choose exactly one option for each of the three survey items below.
- Favorite subject: one of 'kor', 'eng', 'math'
- Favorite fruit: one of 'apple', 'pear', 'orange'
- Favorite color: one of 'red', 'blue', 'green'
Process queries in order on the preferences of the students. Each query is as follows.
- The query format is 'subject fruit color'.
- subject is one of 'kor', 'eng', 'math', or '-'.
- fruit is one of 'apple', 'pear', 'orange', or '-'.
- color is one of 'red', 'blue', 'green', or '-'.
- '-' means that condition is not considered.
- Print the number of students among the whose preferences match subject fruit color.
Given the preferences of the students and queries, process the queries in order. and are very large, so help the students who are stuck on them.
Input
The first line contains and , separated by a space.
Each of the next lines contains one student's preferences: favorite subject, fruit, and color, separated by spaces.
Each of the next lines contains one query: subject, fruit, and color, separated by spaces.
Output
Print the result of each query on its own line, in order, as an integer.
Constraints
1 ≤ , ≤ 100,000