結果

問題 No.1170 Never Want to Walk
ユーザー qLethonqLethon
提出日時 2020-08-14 21:44:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,524 bytes
コンパイル時間 2,564 ms
コンパイル使用メモリ 201,352 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-18 21:24:36
合計ジャッジ時間 8,623 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 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 1 ms
5,376 KB
testcase_08 AC 1 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 4 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 7 ms
5,376 KB
testcase_23 AC 4 ms
5,376 KB
testcase_24 AC 6 ms
5,376 KB
testcase_25 AC 7 ms
5,376 KB
testcase_26 AC 6 ms
5,376 KB
testcase_27 AC 347 ms
5,760 KB
testcase_28 AC 340 ms
5,632 KB
testcase_29 AC 352 ms
5,632 KB
testcase_30 AC 346 ms
5,760 KB
testcase_31 AC 337 ms
5,504 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 Abel>
class UnionFind{
    vector<int> par_, weight_;
public:
    UnionFind(size_t n){
        par_.assign(n, -1);
        weight_.assign(n, 0);
    }

    int root(int x){
        if (par_[x] < 0) {
            return x;
        }else{
            int res = root(par_[x]);
            weight_[x] += weight_[par_[x]];
            return par_[x] = res;
        }
    }

    int weight(int x){
        root(x);
        return weight_[x];
    }

    int weight(int x, int y){
        return weight(y) - weight(x);
    }

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

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

    void Merge(int x, int y, Abel w){
        w += weight(x);
        w -= weight(y);
        x = root(x);
        y = root(y);
        if (x == y)
            return;
        if (size(x) < size(y)) {
            w = -w;
            swap(x, y);
        }
        par_[x] += par_[y];
        par_[y] = x;
        weight_[y] = w;
    }
};

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> X(n);
    copy_n(istream_iterator<int>(cin), n, X.begin());

    int l = 0, r = 0;
    UnionFind<int> uf(n);
    for (int i = 0; i < n; i++){
        while (r < n and X[r] - X[i] <= b)
            r++;
        while (l < n and X[l] - X[i] < a)
            l++;
        for (int j = l; j < r; j++)
            uf.Merge(i, j, 0);
    }

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