#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x ostream& operator<<(ostream& os, const pair& p){ return os << "{" << p.first << ", " << p.second << "}"; } template ostream& operator<<(ostream& os, const vector& obj) { os << "{"; for (const auto& e : obj) os << e << ", "; return os << "}"; } template ostream& operator<<(ostream& os, const set& obj) { os << "set{"; for (const auto& e : obj) os << e << ", "; return os << "}"; } template ostream& operator<<(ostream& os, const map& obj) { os << "map{"; for (const auto& e : obj) os << e << ", "; return os << "}"; } #ifdef ONLINE_JUDGE #define dump(expr) ; #else #define dump(expr) { cerr << "\033[33m#L" << __LINE__ << ": " << expr << "\033[39m" << endl; } #endif namespace solver { const ll mod = 998244353; ll mul(ll a, ll b) { return (a * b) % mod; } ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); } int n; ll m; vector vx, vy, vh; void read() { cin >> n >> m; vx.resize(n); vy.resize(n); vh.resize(n); for (int i : range(n)) { cin >> vx[i] >> vy[i] >> vh[i]; } } ll run() { map mpx, mpy; for (int i : range(n)) { ll r = m - vh[i]; ll x = vx[i], y = vy[i]; mpx[x + y - r]++; mpx[x + y + r]++; mpy[x - y - r]++; mpy[x - y + r]++; } ll a = 0, b = 0; for (auto& it : mpx) it.second = a++; for (auto& it : mpy) it.second = b++; dump(mpx) dump(mpy) vector> ps(a + 1, vector(b + 1)); for (int i : range(n)) { ll r = m - vh[i]; ll x = vx[i], y = vy[i]; ll x1 = mpx[x + y - r] + 1; ll x2 = mpx[x + y + r] + 1; ll y1 = mpy[x - y - r] + 1; ll y2 = mpy[x - y + r] + 1; ps[x1][y1]++; ps[x2][y1]--; ps[x1][y2]--; ps[x2][y2]++; } dump(ps) for (int i : range(1, a + 1)) for (int j : range(1, b + 1)) ps[i][j] += ps[i - 1][j] + ps[i][j - 1] - ps[i - 1][j - 1]; dump(ps) vector wx(a), wy(b); for (auto it = mpx.begin(); ; it++) { auto jt = it; if (++jt == mpx.end()) break; wx[it->second] = jt->first - it->first; } for (auto it = mpy.begin(); ; it++) { auto jt = it; if (++jt == mpy.end()) break; wy[it->second] = jt->first - it->first; } dump(wx) dump(wy) dump(n) vector ans(n + 1); dump(ans) for (int i : range(1, a + 1)) for (int j : range(1, b + 1)) { ll sum = ps[i][j]; ans[sum] += wx[i - 1] * wy[j - 1]; } dump(ans); for (int i : range(1, 1 + n)) cout << mul(inv(2, mod), ans[i] % mod) << endl; return 0; } } int main(int argc, char** argv) { cout << fixed << setprecision(12); int testcase = 1; if (argc > 1) testcase = atoi(argv[1]); while (testcase--) { solver::read(); } // cout << solver::run() << endl; solver::run(); }