結果

問題 No.1170 Never Want to Walk
ユーザー ohaini1123ohaini1123
提出日時 2020-08-15 12:10:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 1,902 bytes
コンパイル時間 1,766 ms
コンパイル使用メモリ 170,972 KB
実行使用メモリ 9,504 KB
最終ジャッジ日時 2023-08-01 01:08:21
合計ジャッジ時間 5,415 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 116 ms
9,120 KB
testcase_28 AC 116 ms
9,204 KB
testcase_29 AC 120 ms
9,272 KB
testcase_30 AC 120 ms
9,200 KB
testcase_31 AC 117 ms
9,216 KB
testcase_32 AC 111 ms
9,108 KB
testcase_33 AC 114 ms
9,136 KB
testcase_34 AC 112 ms
9,048 KB
testcase_35 AC 111 ms
9,180 KB
testcase_36 AC 109 ms
9,216 KB
testcase_37 AC 110 ms
9,196 KB
testcase_38 AC 115 ms
9,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;
using P = pair<ll,ll>;
using graph = vector<vector<int>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T>
struct UnionFind {
    vector<T> par,rank,large;

    void init(T N){
        rank.assign(N,0);
        large.assign(N,1);
        par.resize(N);
        for(T i= 0; i < N; i++){
            par[i]=i;
        }
    }

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

    void unite(T x, T y) {
        T rx = root(x);
        T ry = root(y);
        if (rx == ry) return;
        if(rank[rx]<rank[ry]) {
            par[rx]=ry;
            large[ry]+=large[rx];
            large[rx]=0;
        }
        else {
            par[ry]=rx;
            large[rx]+=large[ry];
            large[ry]=0;
            if(rank[rx]==rank[ry])rank[x]++;
        }
    }

    bool same(T x, T y) {
        T rx = root(x);
        T ry = root(y);
        return rx == ry;
    }

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

int main(){
  ll N,A,B;
  cin>>N>>A>>B;
  vector<ll> v(N);
  rep(i,N) cin>>v[i];
  UnionFind<ll> tree;
  tree.init(N);
  int p=0,q=0;
  rep(i,N){
    int s = lower_bound(v.begin(),v.end(),v[i]+A) - v.begin(),t = upper_bound(v.begin(),v.end(),v[i]+B) - v.begin();
    if(s>=t) continue;
    if(q<=s){
      for(int j = s; j < t; j++){
        tree.unite(i,j);
      }
    }
    else {
      tree.unite(i,i-1);
      for(int j = q; j<t; j++) tree.unite(i,j);
    }
    p=s,q=t;
  }
  rep(i,N){
    printf("%lld\n",tree.size(i));
  }
}
0