#P2058. [NOIP 2016 普及组] 海港

[NOIP 2016 普及组] 海港

Description

Xiao K is a customs officer at a harbor. Many ships arrive at the harbor every day, and there are usually many passengers on board from different countries.

Xiao K is very interested in these ships that arrive at the harbor. He records every ship in chronological order. For the ii-th arriving ship, he records its arrival time tit_i (in seconds), the number of passengers kik_i, and the nationality of each passenger xi,1,xi,2,,xi,kix_{i,1}, x_{i,2}, \dots, x_{i,k_i}.

Xiao K has collected information about nn ships. Please help him compute, for each ship’s arrival time, how many distinct countries the passengers come from among all ships that arrived within the last 2424 hours (2424 hours =86400= 86400 seconds), up to and including that time.

Formally, you need to compute nn values. For the ii-th output, consider all ships pp satisfying ti86400<tptit_i - 86400 < t_p \le t_i. Among all xp,jx_{p,j} in these ships, count how many distinct values there are.

Input Format

The first line contains a positive integer nn, indicating that Xiao K recorded information about nn ships.

Each of the next nn lines describes one ship: the first two integers tit_i and kik_i denote the ship’s arrival time and the number of passengers on board, followed by kik_i integers xi,jx_{i,j}, which are the nationalities of the passengers.

It is guaranteed that the tit_i are nondecreasing, measured in seconds. Counting from when Xiao K first started working, the ii-th ship arrives at second tit_i.

It is guaranteed that 1n1051 \le n \le 10^5, ki3×105\sum k_i \le 3 \times 10^5, 1xi,j1051 \le x_{i,j} \le 10^5, 1ti1ti1091 \le t_{i-1} \le t_i \le 10^9.

Here, ki\sum k_i denotes the sum of all kik_i.

Output Format

Output nn lines. On the ii-th line, output one integer: the required statistic after the ii-th ship arrives.

3
1 4 4 1 2 2
2 2 2 3
10 1 3
3
4
4

4
1 4 1 2 2 3
3 2 2 3
86401 2 3 4
86402 1 5
3
3
3
4

Hint

Sample Explanation 1:

The first ship arrives at second 11. The ships that arrived in the last 2424 hours are just the first ship, with 44 passengers from countries 4,1,2,24, 1, 2, 2, for a total of 33 distinct countries.

The second ship arrives at second 22. The ships that arrived in the last 2424 hours are the first and second ships, with 4+2=64 + 2 = 6 passengers from countries 4,1,2,2,2,34, 1, 2, 2, 2, 3, for a total of 44 distinct countries.

The third ship arrives at second 1010. The ships that arrived in the last 2424 hours are the first, second, and third ships, with 4+2+1=74 + 2 + 1 = 7 passengers from countries 4,1,2,2,2,3,34, 1, 2, 2, 2, 3, 3, for a total of 44 distinct countries.

Sample Explanation 2:

The first ship arrives at second 11. The ships that arrived in the last 2424 hours are just the first ship, with 44 passengers from countries 1,2,2,31, 2, 2, 3, for a total of 33 distinct countries.

The second ship arrives at second 33. The ships that arrived in the last 2424 hours are the first and second ships, with 4+2=64 + 2 = 6 passengers from countries 1,2,2,3,2,31, 2, 2, 3, 2, 3, for a total of 33 distinct countries.

The third ship arrives at second 8640186401. The ships that arrived in the last 2424 hours are the second and third ships, with 2+2=42 + 2 = 4 passengers from countries 2,3,3,42, 3, 3, 4, for a total of 33 distinct countries.

The fourth ship arrives at second 8640286402. The ships that arrived in the last 2424 hours are the second, third, and fourth ships, with 2+2+1=52 + 2 + 1 = 5 passengers from countries 2,3,3,4,52, 3, 3, 4, 5, for a total of 44 distinct countries.

Constraints

  • For 10%10\% of the test points, $n = 1, \sum k_i \leq 10, 1 \leq x_{i,j} \leq 10, 1 \leq t_i \leq 10$.
  • For 20%20\% of the test points, $1 \leq n \leq 10, \sum k_i \leq 100, 1 \leq x_{i,j} \leq 100, 1 \leq t_i \leq 32767$.
  • For 40%40\% of the test points, $1 \leq n \leq 100, \sum k_i \leq 100, 1 \leq x_{i,j} \leq 100, 1 \leq t_i \leq 86400$.
  • For 70%70\% of the test points, $1 \leq n \leq 1000, \sum k_i \leq 3000, 1 \leq x_{i,j} \leq 1000, 1 \leq t_i \leq 10^9$.
  • For 100%100\% of the test points, $1 \leq n \leq 10^5, \sum k_i \leq 3 \times 10^5, 1 \leq x_{i,j} \leq 10^5, 1 \leq t_i \leq 10^9$.

Translated by ChatGPT 5