結果
問題 |
No.1170 Never Want to Walk
|
ユーザー |
![]() |
提出日時 | 2020-08-15 15:37:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,189 bytes |
コンパイル時間 | 3,274 ms |
コンパイル使用メモリ | 200,920 KB |
最終ジャッジ日時 | 2025-01-13 01:32:01 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 15 WA * 15 TLE * 7 |
ソースコード
#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; class Dis{ public: vector<ll> rank,p,siz; Dis(int s){ rank.resize(s,0); p.resize(s,0); siz.resize(s,1); rep(i,s) makeSet(i); } void makeSet(int x){ p[x]=x; rank[x]=0; } bool same(int x,int y){ return findSet(x)==findSet(y); } void unite(int x,int y){ if(same(x,y)) return; link(findSet(x),findSet(y)); } void link(int x,int y){ if(rank[x]>rank[y]){ p[y]=x; siz[x]+=siz[y]; } else{ p[x]=y; siz[y]+=siz[x]; if(rank[x]==rank[y]) rank[y]++; } } int findSet(int x){ if(x != p[x]) p[x]=findSet(p[x]); return p[x]; } ll size(int x){ return siz[p[x]]; } }; int main(){ ll n,a,b; cin>>n>>a>>b; Dis ds=Dis(n); vector<ll> A(n); rep(i,n) cin>>A[i]; rep(i,n){ auto it1=lower_bound(ALL(A),A[i]+a); auto it2=upper_bound(ALL(A),A[i]+b); for(auto j=it1;j<it2;j++){ ds.unite(i,j-A.begin()); } } rep(i,n){ cout<<ds.size(i)<<endl; } return 0; }