結果

問題 No.1170 Never Want to Walk
ユーザー oevloevl
提出日時 2020-08-15 00:58:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 1,175 bytes
コンパイル時間 2,478 ms
コンパイル使用メモリ 198,464 KB
実行使用メモリ 5,632 KB
最終ジャッジ日時 2024-04-18 23:25:51
合計ジャッジ時間 5,831 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 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 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 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 2 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 126 ms
5,504 KB
testcase_28 AC 123 ms
5,632 KB
testcase_29 AC 130 ms
5,632 KB
testcase_30 AC 128 ms
5,504 KB
testcase_31 AC 126 ms
5,632 KB
testcase_32 AC 120 ms
5,632 KB
testcase_33 AC 125 ms
5,504 KB
testcase_34 AC 123 ms
5,632 KB
testcase_35 AC 122 ms
5,504 KB
testcase_36 AC 120 ms
5,632 KB
testcase_37 AC 120 ms
5,504 KB
testcase_38 AC 124 ms
5,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

class UnionFind {
public:
    vector<int> uni;
    UnionFind(int s) : uni(s, -1) {}
    int root(int a) {
        return uni[a] < 0 ? a : uni[a] = root(uni[a]);
    }
    bool connect(int a, int b) {
        a = root(a);
        b = root(b);
        if(a == b) return false;
        if(uni[a] > uni[b]) swap(a, b);
        uni[a] = uni[a] + uni[b];
        uni[b] = a;
        return true;
    }
    bool isConnect(int a, int b) {
        return root(a) == root(b);
    }
    int size(int a) {
        return -uni[root(a)];
    }
};

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    vector<int> X(N);
    for(auto &e : X) cin >> e;
    UnionFind uf(N);
    vector<int> cum(N + 1);
    rep(i, N) {
        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) continue;
        uf.connect(i, l);
        cum[l]++, cum[r]--;
    }
    rep(i, N) cum[i + 1] += cum[i];
    rep(i, N) if(cum[i]) uf.connect(i, i + 1);
    rep(i, N) cout << uf.size(i) << '\n';
    return 0;
}
0