用时:24ms
C++ 代码
#include<iostream>
using namespace std;
const int N = 101;
int cnt[N] = {}; // 记录单词总共出现次数
int page[N] = {}; // 记录单词出现的文章数
int main() {
// n: 文章篇数;m: 每篇文章的单词上限
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
int w, num;
bool judge[N] = {}; // 防止重复记录文章数
cin >> w;
while (w--) {
cin >> num;
cnt[num]++;
if (judge[num] == 0) page[num]++;
judge[num] = 1;
}
}
for (int i = 1; i <= m; i++) {
printf("%d %d\n", page[i], cnt[i]);
}
return 0;
}