結果

問題 No.1170 Never Want to Walk
ユーザー umezoumezo
提出日時 2024-01-24 02:51:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 1,839 bytes
コンパイル時間 8,075 ms
コンパイル使用メモリ 228,164 KB
実行使用メモリ 37,632 KB
最終ジャッジ日時 2024-01-24 02:52:17
合計ジャッジ時間 10,938 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 3 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 3 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 3 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 271 ms
27,520 KB
testcase_28 AC 259 ms
27,136 KB
testcase_29 AC 278 ms
28,032 KB
testcase_30 AC 270 ms
27,904 KB
testcase_31 AC 267 ms
27,264 KB
testcase_32 AC 275 ms
36,224 KB
testcase_33 AC 250 ms
30,080 KB
testcase_34 AC 285 ms
36,992 KB
testcase_35 AC 278 ms
36,676 KB
testcase_36 AC 263 ms
35,328 KB
testcase_37 AC 273 ms
36,340 KB
testcase_38 AC 285 ms
37,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0