結果

問題 No.1170 Never Want to Walk
ユーザー boutarouboutarou
提出日時 2020-08-14 23:42:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 359 ms / 2,000 ms
コード長 1,578 bytes
コンパイル時間 2,139 ms
コンパイル使用メモリ 169,884 KB
実行使用メモリ 6,596 KB
最終ジャッジ日時 2024-04-18 23:19:57
合計ジャッジ時間 8,012 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 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 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 333 ms
6,324 KB
testcase_28 AC 338 ms
6,432 KB
testcase_29 AC 328 ms
6,484 KB
testcase_30 AC 342 ms
6,420 KB
testcase_31 AC 332 ms
6,308 KB
testcase_32 AC 342 ms
6,576 KB
testcase_33 AC 315 ms
6,552 KB
testcase_34 AC 345 ms
6,576 KB
testcase_35 AC 330 ms
6,596 KB
testcase_36 AC 337 ms
6,308 KB
testcase_37 AC 318 ms
6,572 KB
testcase_38 AC 359 ms
6,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
*    author:  boutarou
*    created: 14.08.2020 22:28:10
**/

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

class UnionFind {
    private:
        vector<int>par;
    public:
        UnionFind(int n) {
            for (int i = 0; i < n; i++) par.push_back(-1);
        }
        int root(int x) {
            if (par[x] < 0) return x;
            else return par[x] = root(par[x]);
        }
        bool same(int x, int y) { return root(x) == root(y);}
        void unite(int x, int y) {
            x = root(x), y = root(y);
            if (x == y) return;
            if (par[x] > par[y]) swap(x, y);
            par[x] += par[y];
            par[y] = x;
            return;
        }
        int size(int x) { return -par[root(x)];}
};

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> x(n);
    rep(i, n) cin >> x[i];
    UnionFind uf(n);
    vector<int> imos(n, 0);
    rep(i, n) {
        int before = lower_bound(x.begin(), x.end(), x[i] + a) - x.begin();
        int after = upper_bound(x.begin(), x.end(), x[i] + b) - x.begin() - 1;
        if (before <= after && (0 <= before && before <= n - 1) && (0 <= after && after <= n - 1)) {
            uf.unite(i, before);
            imos[before]++, imos[after]--;
        }
    }
    for (int i = 1; i <= n - 2; i++) {
        imos[i] += imos[i - 1];
    }
    rep(i, n - 1) {
        if (imos[i] > 0) uf.unite(i, i + 1);
    }
    rep(i, n) {
        cout << uf.size(i) << endl;
    }
    return 0;
}
0