P16031 [CSPro 33] Word Frequency Statistics
Background
Luogu's testdata is only for non-official communication and use, and is not official testdata. Official judging link: 。
Description
After learning text processing, Little P did some initial organization of $n$ articles in an English book. Specifically, Little P converted all English words into integer IDs. Suppose that across these $n$ articles, there are $m$ distinct words in total, then number them from $1$ to $m$. In this way, each article is simplified into an integer sequence, where each number is in the range from $1$ to $m$.
Now you are given the $n$ articles processed by Little P. For each word $i$ ($1 \le i \le m$), count:
1. In how many articles does word $i$ appear?
2. How many times does word $i$ appear in total across all articles?
Input Format
Read input from standard input.
The input has a total of $n + 1$ lines.
The first line contains two positive integers $n$ and $m$, representing the number of articles and the upper bound of word IDs.
Line $i + 1$ ($1 \le i \le n$) contains several integers separated by spaces. The first integer $l_i$ is the length (number of words) of the $i$-th article; the next $l_i$ integers give the corresponding integer sequence. Each integer in the sequence is in the range from $1$ to $m$, and each corresponds to a word in the original text.
Output Format
Write output to standard output.
Output a total of $m$ lines.
On line $i$ ($1 \le i \le m$), output two integers $x_i$ and $y_i$ separated by a space, meaning that there are $x_i$ articles containing word $i$, and the total number of occurrences is $y_i$.
Explanation/Hint
### Sample Explanation
Word $2$ appears:
- Twice in article $1$;
- Three times in article $3$;
- Once in article $4$.
Therefore, $x_2 = 3$ and $y_2 = 6$。
### Subtasks
All testdata satisfies $0 < n, m \le 100$, and each article contains at least one word and at most $100$ words ($1 \le l_i \le 100$)。
Translated by ChatGPT 5