結果

問題 No.1170 Never Want to Walk
ユーザー ohaini1123ohaini1123
提出日時 2020-08-15 12:00:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,760 bytes
コンパイル時間 1,904 ms
コンパイル使用メモリ 168,960 KB
実行使用メモリ 16,416 KB
最終ジャッジ日時 2024-04-18 23:59:22
合計ジャッジ時間 6,975 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,884 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 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 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 121 ms
9,344 KB
testcase_28 AC 124 ms
9,344 KB
testcase_29 AC 122 ms
9,472 KB
testcase_30 AC 121 ms
9,728 KB
testcase_31 AC 125 ms
9,344 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

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);
  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()-1;
    if(s>t) continue;
    for(int j = s; j <= t; j++){
      tree.unite(i,j);
    }
  }
  rep(i,N){
    printf("%lld\n",tree.size(i));
  }
}
0