結果

問題 No.1170 Never Want to Walk
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2020-08-14 23:58:50
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 852 ms / 2,000 ms
コード長 1,958 bytes
コンパイル時間 1,176 ms
コンパイル使用メモリ 129,648 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-18 23:21:19
合計ジャッジ時間 12,838 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 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 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 6 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 6 ms
5,376 KB
testcase_18 AC 5 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 5 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 6 ms
5,376 KB
testcase_23 AC 6 ms
5,376 KB
testcase_24 AC 5 ms
5,376 KB
testcase_25 AC 5 ms
5,376 KB
testcase_26 AC 6 ms
5,376 KB
testcase_27 AC 785 ms
10,624 KB
testcase_28 AC 773 ms
10,496 KB
testcase_29 AC 798 ms
10,880 KB
testcase_30 AC 805 ms
10,880 KB
testcase_31 AC 751 ms
10,752 KB
testcase_32 AC 812 ms
10,752 KB
testcase_33 AC 792 ms
10,624 KB
testcase_34 AC 852 ms
10,752 KB
testcase_35 AC 828 ms
10,752 KB
testcase_36 AC 799 ms
10,752 KB
testcase_37 AC 804 ms
10,624 KB
testcase_38 AC 824 ms
11,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

struct unionfind {
    vector<long long> par,_size,_right,_left;
    unionfind(long n) : par(n+1), _size(n+1,1), _right(n+1), _left(n+1) {
        iota(par.begin(), par.end(), 0);
        iota(_right.begin(), _right.end(), 0);
        iota(_left.begin(), _left.end(), 0);
    }
    void init(long long n) {
        par = vector<long long>(n);
        _size = vector<long long>(n);
        for(long long i=0; i<n; i++) par[i]=i;
    }
    long long root(long long x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    long long right(long long x) {return _right[root(x)];}
    long long left(long long x) {return _left[root(x)];}
    bool merge(long long x, long long y) {
        x = root(x);
        y = root(y);
        if (x==y) return false;
        if(_size[x]<_size[y]) swap(x,y);
        _left[x] = min(_left[x], _left[y]);
        _right[x] = max(_right[x], _right[y]);
        _size[x] += _size[y];
        par[y] = x;
        return true;
    }
    void merge_range(long long x, long long y) {
        if (x > y) return;
        while(right(x) < y) this->merge(right(x), right(x)+1);
    }
    bool issame(long long x, long long y) { return root(x) == root(y); }
    long long size(long long x) { return _size[root(x)]; }
};

int main() {
    int n,a,b;
    cin >> n >> a >> b;
    vector x(n,0);
    for (int i=0; i<n; i++) cin >> x[i];
    unionfind uni(n);

    vector imos(n+1, 0);
    for (int i=0; i<n-1; i++) {
        auto l = lower_bound(x.begin(), x.end(), x[i]+a);
        auto r = upper_bound(x.begin(), x.end(), x[i]+b);
        if (l >= r) continue;
        int lindex = l - x.begin();
        int rindex = r - x.begin();
        uni.merge(i, lindex);
        uni.merge_range(lindex, rindex-1);
        cerr<<i<<endl;
    }

    for (int i=0; i<n; i++) {
        cout << uni.size(i) << endl;
    }
}
0