結果
| 問題 |
No.2520 L1 Explosion
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2023-10-28 00:04:34 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,499 ms / 2,000 ms |
| コード長 | 3,777 bytes |
| コンパイル時間 | 4,687 ms |
| コンパイル使用メモリ | 268,016 KB |
| 最終ジャッジ日時 | 2025-02-17 16:19:18 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001
int main(){
long long N,M;
cin>>N>>M;
vector<long long> x(N),y(N),h(N);
rep(i,N){
cin>>x[i]>>y[i]>>h[i];
long long t = x[i];
long long s = y[i];
x[i] = t+s;
y[i] = t-s;
}
vector<pair<long long,long long>> a,b,c,d;
vector<pair<long long,long long>> tx,ty;
rep(i,N){
if(h[i]>M)continue;
long long rem = M - h[i];
a.emplace_back(x[i]-rem,0);
b.emplace_back(x[i]+rem,0);
c.emplace_back(y[i]-rem,0);
d.emplace_back(y[i]+rem,0);
tx.emplace_back(x[i]-rem,0);
tx.emplace_back(x[i]+rem,0);
ty.emplace_back(y[i]-rem,0);
ty.emplace_back(y[i]+rem,0);
}
sort(tx.begin(),tx.end(),[&](pair<long long,long long> x,pair<long long,long long> y){
long long A = x.first-y.first;
long long B = y.second-x.second;
if(A*B<=0)return A<B;
if(A>0){
return A*A < B*B * 2LL;
}
else{
return A*A > B*B * 2LL;
}
});
sort(ty.begin(),ty.end(),[&](pair<long long,long long> x,pair<long long,long long> y){
long long A = x.first-y.first;
long long B = y.second-x.second;
if(A*B<=0)return A<B;
if(A>0){
return A*A < B*B * 2LL;
}
else{
return A*A > B*B * 2LL;
}
});
{
vector<pair<long long,long long>> t;
rep(i,tx.size()){
if(t.size()==0 || t.back()!=tx[i])t.push_back(tx[i]);
}
tx = t;
}
{
vector<pair<long long,long long>> t;
rep(i,ty.size()){
if(t.size()==0 || t.back()!=ty[i])t.push_back(ty[i]);
}
ty = t;
}
vector imos(tx.size()+1,vector<long long>(ty.size()+1));
rep(i,a.size()){
int aa = distance(tx.begin(),lower_bound(tx.begin(),tx.end(),a[i],
[&](pair<long long,long long> x,pair<long long,long long> y){
long long A = x.first-y.first;
long long B = y.second-x.second;
if(A*B<=0)return A<B;
if(A>0){
return A*A < B*B * 2LL;
}
else{
return A*A > B*B * 2LL;
}
}));
int bb = distance(tx.begin(),lower_bound(tx.begin(),tx.end(),b[i],
[&](pair<long long,long long> x,pair<long long,long long> y){
long long A = x.first-y.first;
long long B = y.second-x.second;
if(A*B<=0)return A<B;
if(A>0){
return A*A < B*B * 2LL;
}
else{
return A*A > B*B * 2LL;
}
}));
int cc = distance(ty.begin(),lower_bound(ty.begin(),ty.end(),c[i],
[&](pair<long long,long long> x,pair<long long,long long> y){
long long A = x.first-y.first;
long long B = y.second-x.second;
if(A*B<=0)return A<B;
if(A>0){
return A*A < B*B * 2LL;
}
else{
return A*A > B*B * 2LL;
}
}));
int dd = distance(ty.begin(),lower_bound(ty.begin(),ty.end(),d[i],
[&](pair<long long,long long> x,pair<long long,long long> y){
long long A = x.first-y.first;
long long B = y.second-x.second;
if(A*B<=0)return A<B;
if(A>0){
return A*A < B*B * 2LL;
}
else{
return A*A > B*B * 2LL;
}
}));
imos[aa][cc]++;
imos[aa][dd]--;
imos[bb][cc]--;
imos[bb][dd]++;
}
rep(i,tx.size()){
rep(j,ty.size()+1)imos[i+1][j] += imos[i][j];
}
rep(i,tx.size()+1){
rep(j,ty.size())imos[i][j+1] += imos[i][j];
}
vector<mint> ans(N+1);
rep(i,tx.size()-1){
rep(j,ty.size()-1){
int num = imos[i][j];
if(num==0)continue;
/*
cout<<tx[i].first<<' '<<tx[i].second<<endl;
cout<<tx[i+1].first<<' '<<tx[i+1].second<<endl;
cout<<ty[j].first<<' '<<ty[j].second<<endl;
cout<<ty[j+1].first<<' '<<ty[j+1].second<<endl;
cout<<endl;
*/
ans[num] += mint(2).inv() *(tx[i+1].first - tx[i].first) * (ty[j+1].first -ty[j].first);
ans[num] += (tx[i+1].second - tx[i].second) * (ty[j+1].second -ty[j].second);
}
}
for(int i=1;i<=N;i++){
cout<<ans[i].val()<<endl;
}
return 0;
}
沙耶花