結果
問題 | No.2520 L1 Explosion |
ユーザー |
|
提出日時 | 2024-06-20 00:28:13 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#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; }#endifnamespace 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();}