結果

問題 No.1170 Never Want to Walk
ユーザー rokahikou1rokahikou1
提出日時 2020-08-16 20:28:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 357 ms / 2,000 ms
コード長 1,988 bytes
コンパイル時間 959 ms
コンパイル使用メモリ 98,048 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-19 18:31:15
合計ジャッジ時間 6,948 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 2 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 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 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 3 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 3 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 330 ms
10,752 KB
testcase_28 AC 337 ms
10,624 KB
testcase_29 AC 342 ms
11,008 KB
testcase_30 AC 350 ms
10,880 KB
testcase_31 AC 340 ms
10,752 KB
testcase_32 AC 332 ms
10,752 KB
testcase_33 AC 346 ms
10,752 KB
testcase_34 AC 333 ms
10,880 KB
testcase_35 AC 343 ms
10,880 KB
testcase_36 AC 339 ms
10,880 KB
testcase_37 AC 340 ms
10,880 KB
testcase_38 AC 357 ms
11,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

// UnionFind
struct UnionFind {
    vector<ll> par;
    vector<ll> siz;

    UnionFind(ll N) : par(N), siz(N, 1LL) {
        for(int i = 0; i < N; i++)
            par[i] = i;
    }
    int root(int x) {
        if(par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry)
            return;
        if(siz[rx] < siz[ry])
            swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
    }
    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    ll size(ll x) { return siz[root(x)]; }
};

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    vector<ll> X(N);
    rep(i, N) cin >> X[i];
    vector<ll> imos(N + 1);
    vector<ll> im(N + 1);
    UnionFind uf(N);
    rep(i, N) {
        auto lit = lower_bound(All(X), X[i] + A);
        auto rit = lower_bound(All(X), X[i] + B + 1);
        if(lit == X.end() || lit == rit)
            continue;
        rit--;
        int l = lit - X.begin(), r = rit - X.begin();
        im[l]++;
        im[r]--;
        uf.unite(i, l);
        uf.unite(i, r);
    }
    rep(i, N) { imos[i + 1] = im[i] + imos[i]; }
    FOR(i, 1, N) {
        if(imos[i])
            uf.unite(i, i - 1);
    }
    rep(i, N) { cout << uf.size(i) << endl; }
    return 0;
}
0