結果

問題 No.1170 Never Want to Walk
ユーザー betrue12betrue12
提出日時 2020-09-01 02:40:07
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 344 ms / 2,000 ms
コード長 1,406 bytes
コンパイル時間 2,529 ms
コンパイル使用メモリ 202,924 KB
実行使用メモリ 6,324 KB
最終ジャッジ日時 2023-08-10 19:16:09
合計ジャッジ時間 10,779 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 3 ms
4,384 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 3 ms
4,384 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 322 ms
5,932 KB
testcase_28 AC 328 ms
5,864 KB
testcase_29 AC 344 ms
6,284 KB
testcase_30 AC 330 ms
6,324 KB
testcase_31 AC 333 ms
6,052 KB
testcase_32 AC 332 ms
5,860 KB
testcase_33 AC 324 ms
5,976 KB
testcase_34 AC 341 ms
6,320 KB
testcase_35 AC 335 ms
6,124 KB
testcase_36 AC 330 ms
5,992 KB
testcase_37 AC 326 ms
6,056 KB
testcase_38 AC 334 ms
6,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

    UnionFind(int n=0){ if(n>0) initialize(n); }
    void initialize(int n){
        par.resize(n);
        sz.assign(n, 1);
        for(int i=0; i<n; i++){
            par[i] = i;
        }
    }

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

    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return false;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        return true;
    }

    bool same(int x, int y){ return find(x) == find(y); }
    int size(int x){ return sz[find(x)]; }
};

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    vector<int> X(N);
    for(int i=0; i<N; i++) cin >> X[i];

    UnionFind uf(N);
    vector<int> imos(N);
    for(int i=0; i<N; i++){
        int l = lower_bound(X.begin(), X.end(), X[i]+A) - X.begin();
        int r = upper_bound(X.begin(), X.end(), X[i]+B) - X.begin() - 1;
        if(l <= r){
            uf.unite(i, l);
            uf.unite(i, r);
            imos[l]++;
            imos[r]--;
        }
    }
    for(int i=0; i<N-1; i++){
        if(imos[i]) uf.unite(i, i+1);
        imos[i+1] += imos[i];
    }

    for(int i=0; i<N; i++) cout << uf.size(i) << endl;
    return 0;
}
0