結果
| 問題 | No.2520 L1 Explosion |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-06-26 18:50:22 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 1,885 ms / 2,000 ms |
| コード長 | 4,710 bytes |
| 記録 | |
| コンパイル時間 | 3,955 ms |
| コンパイル使用メモリ | 299,380 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-26 18:50:46 |
| 合計ジャッジ時間 | 20,911 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) ((int)a.size())
#ifdef Doludu
template <typename T>
ostream& operator << (ostream &o, vector <T> 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 <typename T> struct P {
T x, y;
P (T _x = 0, T _y = 0) : x(_x), y(_y) {}
P<T> operator + (P<T> o) {
return P<T>(x + o.x, y + o.y);}
P<T> operator - (P<T> o) {
return P<T>(x - o.x, y - o.y);}
P<T> operator * (T k) {return P<T>(x * k, y * k);}
P<T> operator / (T k) {return P<T>(x / k, y / k);}
__int128 operator * (P<T> o) {return (__int128)x * o.x + (__int128)y * o.y;}
__int128 operator ^ (P<T> o) {return (__int128)x * o.y - (__int128)y * o.x;}
bool operator == (P<T> o) { return sign(x - o.x) == 0 && sign(y - o.y) == 0; }
};
using Pt = P<ll>;
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<vector<Pt>> poly, int id) {
auto get = [&](vector<Pt> &p, int i) {
return make_pair(p[i], p[(i + 1) % sz(p)]); };
vector<pair<Pt, Pt>> seg;
for (int e = 0; e < sz(poly[id]); ++e) {
auto [s, t] = get(poly[id], e);
vector<pair<Pt, int>> 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<vector<Pt>> 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 <vector <Pt>> 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 <ll> 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";
}