結果
問題 |
No.1170 Never Want to Walk
|
ユーザー |
![]() |
提出日時 | 2024-01-24 02:51:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 272 ms / 2,000 ms |
コード長 | 1,839 bytes |
コンパイル時間 | 2,338 ms |
コンパイル使用メモリ | 216,912 KB |
最終ジャッジ日時 | 2025-02-18 22:29:15 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 37 |
ソースコード
#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 root(x)==root(y); } void unite(int x,int y){ if(same(x,y)) return; link(root(x),root(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 root(int x){ if(x != p[x]) p[x]=root(p[x]); return p[x]; } int size(int x){ return siz[root(x)]; } }; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n,a,b; cin>>n>>a>>b; Dis ds=Dis(n); vector<int> X(n); map<int,int> m; set<int> s; rep(i,n){ cin>>X[i]; m[X[i]]=i; s.insert(X[i]); } queue<int> que; rep(i,n){ if(!s.count(X[i])) continue; s.erase(X[i]); que.push(X[i]); while(que.size()){ auto t=que.front(); que.pop(); auto l=s.lower_bound(t+a); auto r=s.upper_bound(t+b); set<int> s1; while(l!=r){ s1.insert(*l); l++; } for(auto x:s1){ ds.unite(i,m[x]); que.push(x); s.erase(x); } l=s.lower_bound(t-b); r=s.upper_bound(t-a); set<int> s2; while(l!=r){ s2.insert(*l); l++; } for(auto x:s2){ ds.unite(i,m[x]); que.push(x); s.erase(x); } } } vector<int> ANS(n); rep(i,n) ANS[ds.root(i)]++; rep(i,n) cout<<ANS[ds.root(i)]<<'\n'; return 0; }