結果

問題 No.1170 Never Want to Walk
ユーザー umezoumezo
提出日時 2020-08-15 15:40:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,195 bytes
コンパイル時間 2,451 ms
コンパイル使用メモリ 201,904 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-19 01:15:14
合計ジャッジ時間 8,987 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 6 ms
5,376 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 6 ms
5,376 KB
testcase_25 AC 6 ms
5,376 KB
testcase_26 AC 5 ms
5,376 KB
testcase_27 AC 357 ms
9,344 KB
testcase_28 AC 353 ms
9,216 KB
testcase_29 AC 360 ms
9,600 KB
testcase_30 AC 363 ms
9,344 KB
testcase_31 AC 357 ms
9,344 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

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 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[findSet(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;
}
0