結果

問題 No.2520 L1 Explosion
ユーザー abc864197532
提出日時 2025-06-26 03:53:41
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 4,110 bytes
コンパイル時間 3,971 ms
コンパイル使用メモリ 293,712 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-06-26 03:53:53
合計ジャッジ時間 11,299 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7 RE * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#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(ll 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);}
  T operator * (P<T> o) {return x * o.x + y * o.y;}
  T operator ^ (P<T> o) {return x * o.y - y * o.x;}
};
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];

void polys_union_area(vector<vector<Pt>> poly) {
  int n = poly.size();
  auto solve = [&](Pt a, Pt b, int cid) {
    vector<pair<Pt, int>> event;
    for (int i = 0; i < n; ++i) {
      int st = 0, sz = poly[i].size();
      while (st < sz && ori(poly[i][st], a, b) != 1)
        st++;
      if (st == sz) continue;
      for (int j = 0; j < sz; ++j) {
        Pt c = poly[i][(j + st) % sz];
        Pt d = poly[i][(j + st + 1) % sz];
        if (sign((a - b) ^ (c - d)) != 0) {
          int ok1 = ori(c, a, b) == 1;
          int ok2 = ori(d, a, b) == 1;
          if (ok1 ^ ok2) event.emplace_back(lines_intersect({a, b}, {c, d}), ok1 ? 1 : -1);
        } else if (ori(c, a, b) == 0 && sign((a - b) * (c - d)) > 0 && i <= cid) {
          event.emplace_back(c, -1);
          event.emplace_back(d, 1);
        }
      }
    }
    sort(all(event), [&](pair<Pt, int> i, pair<Pt, int> j) {
      return ((a - i.first) * (a - b)) < ((a - j.first) * (a - b));
    });
    int now = 0;
    Pt lst = a;
    for (auto [x, y] : event) {
      if (btw(a, b, lst) && btw(a, b, x))
        ans[now] += lst ^ x;
      now += y, lst = x;
    }
  };
  for (int i = 0; i < n; ++i) {
    int sz = poly[i].size();
    for (int j = 0; j < sz; ++j)
      solve(poly[i][j], poly[i][(j + 1) % sz], 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";
}
0