#P2058. Unique Passenger Nationalities

    ID: 15340 Type: Default 1000ms 256MiB

Unique Passenger Nationalities

Unique Passenger Nationalities

Little K is a customs officer at a harbor. Every day many ships arrive, each carrying several passengers from various countries. For the i-th arriving ship, Little K records its arrival time \(t_i\) (in seconds), the number of passengers \(k_i\), and the nationality of each passenger \(x_{i,1}, x_{i,2}, \dots, x_{i,k_i}\).

Your task is to process the information for \(n\) ships. For each ship \(i\), compute the number of distinct nationalities among all passengers from the ships that arrived in the time interval \((t_i-86400,\ t_i]\). Here, note that 24 hours is defined as \(86400\) seconds and the interval is open on the left and closed on the right, i.e. a ship arriving exactly at time \(t_i-86400\) is not included.

Input Format: The first line contains a single integer \(n\), the number of ships. Each of the following \(n\) lines describes a ship. The line starts with two integers \(t_i\) and \(k_i\), followed by \(k_i\) tokens denoting the nationality code of each passenger. You can assume that the ships are listed in the order of their arrival times (i.e. non-decreasing \(t_i\)).

Output Format: For each ship, output an integer on a new line representing the number of distinct nationalities among the passengers in the ships that arrived in the last 24 hours up to and including the current ship.

In mathematical terms, for each \(i\) \((1 \leq i \leq n)\), count the number of distinct values among \(\bigcup_{p:\;t_i-86400 < t_p \leq t_i} \{x_{p,1}, x_{p,2}, \dots, x_{p,k_p}\}\).

inputFormat

The input begins with an integer \(n\) (the number of ships). The following \(n\) lines each contain the information for one ship. Each line starts with two integers \(t_i\) (arrival time in seconds) and \(k_i\) (number of passengers), followed by \(k_i\) tokens representing the nationality codes of the passengers.

outputFormat

Output \(n\) lines, where the \(i\)-th line contains a single integer representing the number of distinct nationalities of passengers from all ships that arrived in the time interval \((t_i-86400, t_i]\).

sample

2
100 2 1 2
200 2 2 3
2

3

</p>