結果

問題 No.1170 Never Want to Walk
ユーザー MASATO338MASATO338
提出日時 2020-08-15 09:28:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 362 ms / 2,000 ms
コード長 1,214 bytes
コンパイル時間 1,907 ms
コンパイル使用メモリ 170,316 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2024-04-18 23:46:31
合計ジャッジ時間 8,306 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 4 ms
6,944 KB
testcase_13 AC 4 ms
6,940 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 3 ms
6,944 KB
testcase_20 AC 4 ms
6,944 KB
testcase_21 AC 3 ms
6,940 KB
testcase_22 AC 3 ms
6,940 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 4 ms
6,940 KB
testcase_25 AC 3 ms
6,944 KB
testcase_26 AC 3 ms
6,940 KB
testcase_27 AC 334 ms
6,940 KB
testcase_28 AC 352 ms
6,940 KB
testcase_29 AC 351 ms
6,944 KB
testcase_30 AC 355 ms
6,940 KB
testcase_31 AC 334 ms
6,940 KB
testcase_32 AC 362 ms
8,320 KB
testcase_33 AC 357 ms
6,944 KB
testcase_34 AC 362 ms
8,320 KB
testcase_35 AC 355 ms
8,192 KB
testcase_36 AC 347 ms
8,064 KB
testcase_37 AC 312 ms
8,192 KB
testcase_38 AC 362 ms
8,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;

struct UnionFind{
  vector<int> par;
  vector<int> sz; //size

  UnionFind(int N): par(N),sz(N){
    for(int i=0;i<N;i++){
      par[i]=i;
      sz[i]=1;
    }
  }

  int root(int x){
    if(par[x]==x) return x;
    else return par[x]=root(par[x]);
  }

  void unite(int x,int y){
    int rx=root(x);
    int ry=root(y);
    if(rx!=ry){
      par[rx]=ry;
      sz[ry] += sz[rx];
    }
  }

  bool sameroot(int x,int y){
    return root(x)==root(y);
  }

  int size(int x){
    return sz[root(x)];
  }
};

int main(){
  ll N,A,B;
  cin>>N>>A>>B;
  vector<ll> x(N);
  for(int i(0);i<N;i++){
    cin>>x[i];
  }
  UnionFind uf(N);
  int fmi(0);
  for(int i(0);i<N;i++){
    int h = x[i]+A,m = x[i]+B;
    int hi = lower_bound(x.begin(),x.end(),h) - x.begin();
    int mi = upper_bound(x.begin(),x.end(),m) - x.begin();
    // cout << "a";
    // cout << hi << " " << mi << endl;
    for(int j(max(hi,fmi-1));j<mi;j++){
      //cout << i << " " << j << endl;
      uf.unite(i,j);
    }
    fmi = mi;
  }
  for(int i(0);i<N;i++){
    cout << uf.size(i) << endl;
  }
  return 0;
}

0