結果

問題 No.1170 Never Want to Walk
ユーザー siro53siro53
提出日時 2020-08-24 17:50:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 2,569 bytes
コンパイル時間 1,893 ms
コンパイル使用メモリ 198,028 KB
実行使用メモリ 5,504 KB
最終ジャッジ日時 2024-04-24 03:39:52
合計ジャッジ時間 4,840 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,248 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 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 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 56 ms
5,376 KB
testcase_28 AC 56 ms
5,504 KB
testcase_29 AC 57 ms
5,504 KB
testcase_30 AC 58 ms
5,376 KB
testcase_31 AC 57 ms
5,504 KB
testcase_32 AC 57 ms
5,504 KB
testcase_33 AC 57 ms
5,504 KB
testcase_34 AC 56 ms
5,376 KB
testcase_35 AC 56 ms
5,504 KB
testcase_36 AC 56 ms
5,504 KB
testcase_37 AC 53 ms
5,504 KB
testcase_38 AC 57 ms
5,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
// #define DEBUG
#ifdef DEBUG
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
#else
template <class T, class... Args>
void debug(const T &x, const Args &... args) {}
template <class T> void debugVector(const vector<T> &v) {}
#endif

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}
    void init(int n) { par.assign(n, -1); }

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

    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(par[x] > par[y])
            swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, A, B;
    cin >> N >> A >> B;
    vector<int> x(N);
    for(int i = 0; i < N; i++) {
        cin >> x[i];
    }
    vector<int> imos(N + 1, 0);
    UnionFind uf(N);
    for(int i = 0; i < N; i++) {
        int l = lower_bound(ALL(x), x[i] + A) - x.begin();
        int r = upper_bound(ALL(x), x[i] + B) - x.begin();
        debug(l, r);
        if(l >= r) {
            continue;
        }
        uf.merge(i, l);
        imos[l]++;
        imos[r - 1]--;
    }
    for(int i = 0; i < N; i++) {
        imos[i + 1] += imos[i];
    }
    for(int i = 0; i < N - 1; i++) {
        if(imos[i] > 0) {
            uf.merge(i, i + 1);
        }
    }
    for(int i = 0; i < N; i++) {
        cout << uf.size(i) << "\n";
    }
}
0