結果

問題 No.1170 Never Want to Walk
ユーザー kyort0nkyort0n
提出日時 2020-08-18 19:54:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 320 ms / 2,000 ms
コード長 2,503 bytes
コンパイル時間 1,836 ms
コンパイル使用メモリ 171,692 KB
実行使用メモリ 9,444 KB
最終ジャッジ日時 2023-08-02 08:12:10
合計ジャッジ時間 10,280 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 312 ms
9,112 KB
testcase_28 AC 307 ms
9,104 KB
testcase_29 AC 316 ms
9,104 KB
testcase_30 AC 319 ms
9,028 KB
testcase_31 AC 315 ms
9,056 KB
testcase_32 AC 319 ms
9,120 KB
testcase_33 AC 318 ms
9,180 KB
testcase_34 AC 320 ms
9,060 KB
testcase_35 AC 315 ms
9,188 KB
testcase_36 AC 308 ms
9,128 KB
testcase_37 AC 316 ms
9,124 KB
testcase_38 AC 320 ms
9,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1e18;
struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
    }

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

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

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

    ll size(int x){
        return Size[root(x)];
    }
};
ll N, A, B;
vector<ll> x;

//const ll mod = 1000000007;
ll imos[201000];
void f(ll L, ll R) {
    auto itr = lower_bound(x.begin(), x.end(), L);
    auto itr2 = lower_bound(x.begin(), x.end(), R+1);
    if(itr2 == itr) return;
    itr2--;
    int idx = itr - x.begin();
    int idx2 = itr2 - x.begin();
    imos[idx]++;
    imos[idx2]--;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> A >> B;
    x.resize(N);
    for(int i = 0; i < N; i++) cin >> x[i];
    UnionFind uni(N);
    for(int i = 0; i < N; i++) {
        auto itr = lower_bound(x.begin(), x.end(), x[i] - B);
        if(*itr <= x[i] - A) {
            int idx = itr - x.begin();
            uni.merge(idx, i);
            f(x[i]-B, x[i]-A);
        }
        itr = lower_bound(x.begin(), x.end(), x[i] + A);
        if(itr != x.end() and *itr <= x[i] + B) {
            int idx = itr - x.begin();
            uni.merge(idx, i);
            f(x[i]+A, x[i]+B);
        }
    }
    for(int i = 0; i < N; i++) {
        imos[i+1] += imos[i];
        if(imos[i] > 0 and i + 1 < N) {
            uni.merge(i, i + 1);
        }
    }
    for(int i = 0; i < N; i++) {
        cout << uni.size(i) << endl;
    }
    return 0;
}
0