結果
問題 |
No.2520 L1 Explosion
|
ユーザー |
![]() |
提出日時 | 2023-10-05 11:24:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 112 ms / 2,000 ms |
コード長 | 2,185 bytes |
コンパイル時間 | 2,034 ms |
コンパイル使用メモリ | 204,976 KB |
最終ジャッジ日時 | 2025-02-17 04:23:08 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define MOD 998244353ll using namespace std; using ll = long long; ll powmod(ll a, ll n){ ll ret = 1; while(n){ if (n & 1) { ret = ret * a % MOD; } a = a * a % MOD; n >>= 1; } return ret; } const ll INV2 = powmod(2, MOD - 2); void set_XY(ll n, ll m, vector<ll>& X1, vector<ll>& Y1, vector<ll>& X2, vector<ll>& Y2, vector<ll>& X, vector<ll>& Y) { for(int i = 0; i < n; ++i){ ll x, y, h; cin >> x >> y >> h; ll d = m - h; ll x1 = (x - d) - y, y1 = (x - d) + y; X1.push_back(x1); Y1.push_back(y1); X.push_back(x1); Y.push_back(y1); ll x2 = (x + d) - y, y2 = (x + d) + y; X2.push_back(x2); Y2.push_back(y2); X.push_back(x2); Y.push_back(y2); } sort(all(X)); X.erase(unique(all(X)), X.end()); sort(all(Y)); Y.erase(unique(all(Y)), Y.end()); } int main(void) { ll n, m; cin >> n >> m; vector<ll> X1 = {}, Y1 = {}, X2 = {}, Y2 = {}, X = {}, Y = {}; set_XY(n, m, X1, Y1, X2, Y2, X, Y); int w = X.size(), h = Y.size(); vector<vector<ll> > dp(w, vector<ll>(h)); for(int i = 0; i < n; ++i){ int x1 = lower_bound(all(X), X1[i]) - X.begin(); int x2 = lower_bound(all(X), X2[i]) - X.begin(); int y1 = lower_bound(all(Y), Y1[i]) - Y.begin(); int y2 = lower_bound(all(Y), Y2[i]) - Y.begin(); dp[x1][y1]++; dp[x2][y1]--; dp[x1][y2]--; dp[x2][y2]++; } for(int i = 0; i < w; ++i){ for(int j = 1; j < h; ++j){ dp[i][j] += dp[i][j - 1]; } } for(int i = 1; i < w; ++i){ for(int j = 0; j < h; ++j){ dp[i][j] += dp[i - 1][j]; } } vector<ll> area(n + 1); for(int i = 0; i < w - 1; ++i){ for(int j = 0; j < h - 1; ++j){ if(dp[i][j] < 1){ continue; } area[dp[i][j]] += ((X[i + 1] - X[i]) % MOD) * ((Y[j + 1] - Y[j]) % MOD) % MOD; } } for(int i = 1; i < n + 1; ++i){ ll ans = area[i] % MOD * INV2 % MOD; cout << ans << endl; } return 0; }