#include using namespace std; typedef long long ll; typedef pair pii; #define pb push_back #define all(a) a.begin(), a.end() #define sz(a) ((int)a.size()) #ifdef Doludu template ostream& operator << (ostream &o, vector vec) { o << "{"; int f = 0; for (T i : vec) o << (f++ ? " " : "") << i; return o << "}"; } void bug__(int c, auto ...a) { cerr << "\e[1;" << c << "m"; (..., (cerr << a << " ")); cerr << "\e[0m" << endl; } #define bug_(c, x...) bug__(c, __LINE__, "[" + string(#x) + "]", x) #define bug(x...) bug_(32, x) #define bugv(x...) bug_(36, vector(x)) #define safe bug_(33, "safe") #else #define bug(x...) void(0) #define bugv(x...) void(0) #define safe void(0) #endif const int mod = 998244353, N = 500005; int sign(__int128 x) { return x == 0 ? 0 : (x > 0 ? 1 : -1); } template struct P { T x, y; P (T _x = 0, T _y = 0) : x(_x), y(_y) {} P operator + (P o) { return P(x + o.x, y + o.y);} P operator - (P o) { return P(x - o.x, y - o.y);} P operator * (T k) {return P(x * k, y * k);} P operator / (T k) {return P(x / k, y / k);} __int128 operator * (P o) {return (__int128)x * o.x + (__int128)y * o.y;} __int128 operator ^ (P o) {return (__int128)x * o.y - (__int128)y * o.x;} bool operator == (P o) { return sign(x - o.x) == 0 && sign(y - o.y) == 0; } }; using Pt = P; struct Line { Pt a, b; }; int ori(Pt o, Pt a, Pt b) { return sign((o - a) ^ (o - b)); } bool btw(Pt a, Pt b, Pt c) // c on segment ab? { return ori(a, b, c) == 0 && sign((c - a) * (c - b)) <= 0; } int pos(Pt a) { return sign(a.y) == 0 ? sign(a.x) < 0 : a.y < 0; } bool cmp(Pt a, Pt b) { return pos(a) == pos(b) ? sign(a ^ b) > 0 : pos(a) < pos(b); } bool same_vec(Pt a, Pt b, int d) // d = 1: check dir { return sign(a ^ b) == 0 && sign(a * b) > d * 2 - 2; } bool same_vec(Line a, Line b, int d) // d = 1: check dir { return same_vec(a.b - a.a, b.b - b.a, d); } Pt perp(Pt a) { return Pt(-a.y, a.x); } // CCW 90 deg Pt lines_intersect(Line a, Line b) { ll sum = 0, sub = 0; if (a.a.x + a.a.y == a.b.x + a.b.y) sum = a.a.x + a.a.y, sub = b.a.x - b.a.y; else sum = b.a.x + b.a.y, sub = a.a.x - a.a.y; return Pt((sum + sub) / 2, (sum - sub) / 2); } __int128 ans[N]; // in CCW order, use index as tiebreaker when collinear void polys_border(vector> poly, int id) { auto get = [&](vector &p, int i) { return make_pair(p[i], p[(i + 1) % sz(p)]); }; vector> seg; for (int e = 0; e < sz(poly[id]); ++e) { auto [s, t] = get(poly[id], e); vector> vec; vec.emplace_back(s, -1 << 30); vec.emplace_back(t, 1 << 30); for (int i = 0; i < sz(poly); ++i) { int st = find_if(all(poly[i]), [&](Pt p) { return ori(p, s, t) == 1; }) - poly[i].begin(); if (st == sz(poly[i])) continue; for (int j = st; j < st + sz(poly[i]); ++j) { auto [a, b] = get(poly[i], j % sz(poly[i])); if (same_vec(a - b, s - t, -1)) { if (ori(a, b, s) == 0 && same_vec(a - b, s - t, 1) && i <= id) { vec.emplace_back(a, -1); vec.emplace_back(b, 1); } } else { int s1 = ori(a, s, t) == 1, s2 = ori(b, s, t) == 1; if (s1 ^ s2) { auto p = lines_intersect({a, b}, {s, t}); vec.emplace_back(p, s1 ? 1 : -1); } } } } Pt v = s - t; sort(all(vec), [&](auto i, auto j) { if (i.first == j.first) return i.second > j.second; if (v.x > 0) return i.first.x > j.first.x; else if (v.x < 0) return i.first.x < j.first.x; else if (v.y > 0) return i.first.y > j.first.y; else return i.first.y < j.first.y; }); int base = 1 << 30; Pt lst(0, 0); for (auto [cur, val] : vec) { if (base < sz(poly)) ans[base] += lst ^ cur; lst = cur, base += val; } } } void polys_union_area(vector> poly) { for (int i = 0; i < sz(poly); ++i) { polys_border(poly, i); } } int main() { ios::sync_with_stdio(false), cin.tie(0); int n, m; cin >> n >> m; vector > polys; for (int i = 0, x, y, h; i < n; ++i) { cin >> x >> y >> h; h = m - h; polys.pb({Pt(x, y - h), Pt(x + h, y), Pt(x, y + h), Pt(x - h, y)}); } for (auto &pp : polys) for (auto &p : pp) p = p * 2; polys_union_area(polys); vector res(n); for (int i = 0; i < n; ++i) { res[i] = (ans[i] % mod) * 873463809 % mod; bug(res[i]); if (i) res[i - 1] = (res[i - 1] + mod - res[i]) % mod; } for (int i = 0; i < n; ++i) cout << res[i] << "\n"; }