結果
問題 |
No.1170 Never Want to Walk
|
ユーザー |
![]() |
提出日時 | 2020-08-14 23:18:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,683 bytes |
コンパイル時間 | 1,846 ms |
コンパイル使用メモリ | 169,424 KB |
実行使用メモリ | 34,048 KB |
最終ジャッジ日時 | 2024-10-10 16:43:48 |
合計ジャッジ時間 | 6,959 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 WA * 5 TLE * 1 -- * 6 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' #define vec vector<ll> #define mat vector<vector<ll> > #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> pll; typedef long double ld; typedef complex<double> comp; const ll inf=1e9+7; const ll mod=2e5+3; const int MAX=1000010; int siz[200010]; int par[200010]; int depth[200010]; void init(int n){ for(int i=0;i<=n;i++){ par[i]=i; depth[i]=0; } rep(i,n+1){ siz[i]=1; } } int root(int x){ return par[x]==x?x:par[x]=root(par[x]); } bool same(int x,int y){ return root(x)==root(y); } void unite(int x,int y){ x=root(x); y=root(y); ll sx=siz[x]; ll sy=siz[y]; if(x==y)return; if(depth[x]<depth[y]){ par[x]=y; }else{ par[y]=x; if(depth[x]==depth[y])depth[x]++; } siz[root(x)]=sx+sy; } vector<ll>x(200010,inf); vector<ll>used(200010); ll a,b; void dfs(ll i){ if(used[i])return; used[i]=1; ll l=lower_bound(all(x),x[i]+a)-x.begin(); ll r=upper_bound(all(x),x[i]+b)-x.begin(); REP(j,l,r){ dfs(j); unite(i,j); } l=lower_bound(all(x),x[i]-b)-x.begin(); r=upper_bound(all(x),x[i]-a)-x.begin(); REP(j,l,r){ dfs(j); unite(i,j); } } signed main(){ ll n;cin>>n>>a>>b; init(n); rep(i,n)cin>>x[i]; rep(i,n){ if(used[i])continue; dfs(i); } rep(i,n){ cout<<siz[root(i)]<<endl; } }