#C11612. Car Inventory Query

    ID: 40948 Type: Default 1000ms 256MiB

Car Inventory Query

Car Inventory Query

You are given an inventory list of cars where each car is characterized by its make and model. Your task is to answer several queries where each query asks for the number of occurrences of a specific car (given as a concatenation of make and model) between two indices (inclusive) in the inventory list.

More formally, you are given an integer (N) representing the number of cars. Next, you are given (N) lines, each containing two strings that denote the make and model of a car. Then you are given an integer (Q) representing the number of queries. Each query consists of two integers (L) and (R) (0-indexed) followed by a string (X) which is the car description in the format "make model". For each query, compute the number of occurrences of (X) among the cars from index (L) to index (R) (inclusive).

The relation can be mathematically represented as: [ \text{result}_i = #{ j \mid L \le j \le R \text{ and } \text{cars}[j] = X } ]

Your solution should read input from standard input (stdin) and print the output to standard output (stdout).

inputFormat

The first line contains an integer (N) denoting the number of cars. The next (N) lines each contain two strings representing the make and model of a car. The following line contains an integer (Q) denoting the number of queries. The next (Q) lines each contain two integers (L) and (R) and a string (X) (which might consist of two words separated by a space) representing the query. All indices are 0-indexed.

outputFormat

For each query, output a single integer on a new line denoting the number of cars matching the queried make and model within the given range.## sample

5
Toyota Corolla
Honda Civic
Toyota Camry
Honda Accord
Toyota Corolla
3
0 4 Toyota Corolla
0 3 Honda Civic
2 4 Toyota Corolla
2

1 1

</p>