結果

問題 No.1170 Never Want to Walk
ユーザー DenteDente
提出日時 2020-08-14 22:23:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,451 bytes
コンパイル時間 2,211 ms
コンパイル使用メモリ 197,468 KB
実行使用メモリ 13,056 KB
最終ジャッジ日時 2024-04-18 22:14:38
合計ジャッジ時間 8,464 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,752 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 5 ms
5,376 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 5 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 5 ms
5,376 KB
testcase_21 AC 5 ms
5,376 KB
testcase_22 AC 5 ms
5,376 KB
testcase_23 AC 5 ms
5,376 KB
testcase_24 AC 5 ms
5,376 KB
testcase_25 AC 5 ms
5,376 KB
testcase_26 AC 5 ms
5,376 KB
testcase_27 AC 347 ms
9,600 KB
testcase_28 AC 344 ms
10,112 KB
testcase_29 AC 364 ms
10,624 KB
testcase_30 AC 352 ms
10,624 KB
testcase_31 AC 353 ms
9,728 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

#define MAX 200000

struct UnionFind {
    vector<int> par, siz;

    UnionFind(int n) : par(n), siz(n, 1) {
        iota(par.begin(), par.end(), 0);
    }

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

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
    }

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

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

int n;
ll a, b;
ll x[MAX];
bool visited[MAX];
UnionFind uf(MAX);

void dfs(int cur) {
    if (visited[cur]) return;
    visited[cur] = true;
    int l = lower_bound(x, x + n, x[cur] + a) - x;
    int r = upper_bound(x, x + n, x[cur] + b) - x;
    if (l < n) dfs(l);
    if (r - 1 > l) dfs(r - 1);
    for (int i = l; i < r; i++) {
        visited[i] = true;
        uf.unite(cur, i);
    }
}

signed main() {
    cin >> n >> a >> b;
    rep(i, n) {
        cin >> x[i];
    }
    rep(i, n) {
        dfs(i);
    }
    rep(i, n) {
        cout << uf.size(i) << endl;
    }
    return 0;
}
0