按照题意模拟即可,需要注意的是 a/b 向上取整可以直接写为 (a+b-1)/b
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 2e5 + 5; int __t = 1, n, m, k, c; void solve() { map<int, int> mp; cin >> n >> m; for (int i = 0; i < n; ++i) { cin >> k >> c; vector<int> ve(k - 1); for (int j = 0; j < k - 1; ++j) cin >> ve[j]; int pos = (c + k - 1) / k; for (int j : ve) mp[j] += pos; } for (int i = 1; i <= m; ++i) cout << mp[i] << " \n"[i == m]; } int32_t main() { #ifdef ONLINE_JUDGE ios::sync_with_stdio(false); cin.tie(0); #endif // cin >> __t; while (__t--) solve(); return 0; }