#P16031. [CSPro 33] 词频统计

[CSPro 33] 词频统计

Background

Luogu's testdata is only for non-official communication and use, and is not official testdata. Official judging link: https://www.cspro.org/。

Problem Description

After learning text processing, Little P did some initial organization of nn articles in an English book. Specifically, Little P converted all English words into integer IDs. Suppose that across these nn articles, there are mm distinct words in total, then number them from 11 to mm. In this way, each article is simplified into an integer sequence, where each number is in the range from 11 to mm.

Now you are given the nn articles processed by Little P. For each word ii (1≤i≤m1 \le i \le m), count:

  1. In how many articles does word ii appear?
  2. How many times does word ii appear in total across all articles?

Input Format

Read input from standard input.

The input has a total of n+1n + 1 lines.

The first line contains two positive integers nn and mm, representing the number of articles and the upper bound of word IDs.

Line i+1i + 1 (1≤i≤n1 \le i \le n) contains several integers separated by spaces. The first integer lil_i is the length (number of words) of the ii-th article; the next lil_i integers give the corresponding integer sequence. Each integer in the sequence is in the range from 11 to mm, and each corresponds to a word in the original text.

Output Format

Write output to standard output.

Output a total of mm lines.

On line ii (1≤i≤m1 \le i \le m), output two integers xix_i and yiy_i separated by a space, meaning that there are xix_i articles containing word ii, and the total number of occurrences is yiy_i.

4 3
5 1 2 3 2 1
1 1
3 2 2 2
2 3 2
2 3
3 6
2 2

Hint

Sample Explanation

Word 22 appears:

  • Twice in article 11;
  • Three times in article 33;
  • Once in article 44.

Therefore, x2=3x_2 = 3 and y2=6y_2 = 6。

Subtasks

All testdata satisfies 0<n,m≤1000 < n, m \le 100, and each article contains at least one word and at most 100100 words (1≤li≤1001 \le l_i \le 100)。

Translated by ChatGPT 5