結果

問題 No.2520 L1 Explosion
ユーザー ir5ir5
提出日時 2024-06-20 00:28:13
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 3,356 bytes
コンパイル時間 2,323 ms
コンパイル使用メモリ 153,684 KB
実行使用メモリ 74,624 KB
最終ジャッジ日時 2024-06-20 00:28:21
合計ジャッジ時間 4,645 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 88 ms
74,368 KB
testcase_07 AC 25 ms
21,504 KB
testcase_08 AC 87 ms
74,624 KB
testcase_09 AC 91 ms
74,496 KB
testcase_10 AC 88 ms
74,368 KB
testcase_11 AC 87 ms
74,496 KB
testcase_12 AC 87 ms
74,368 KB
testcase_13 AC 86 ms
74,368 KB
testcase_14 AC 87 ms
74,496 KB
testcase_15 AC 5 ms
6,940 KB
testcase_16 AC 64 ms
54,272 KB
testcase_17 AC 41 ms
35,712 KB
testcase_18 AC 43 ms
37,120 KB
testcase_19 AC 36 ms
30,976 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 58 ms
50,432 KB
testcase_22 AC 9 ms
8,960 KB
testcase_23 AC 6 ms
6,940 KB
testcase_24 AC 49 ms
43,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <functional>
#include <iomanip>
using namespace std;
using ll = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n_):i({0}),n({n_}){}range(int i_,int n_):i({i_}),n({n_}){}I& begin(){return i;}I& end(){return n;}};

template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& obj) { os << "{"; for (const auto& e : obj) os << e << ", "; return os << "}"; }
template<typename T> ostream& operator<<(ostream& os, const set<T>& obj) { os << "set{"; for (const auto& e : obj) os << e << ", "; return os << "}"; }
template<typename T, typename U> ostream& operator<<(ostream& os, const map<T, U>& 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<ll> 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<ll, ll> 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<vector<ll>> ps(a + 1, vector<ll>(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<ll> 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<ll> 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();
}
0