結果

問題 No.1170 Never Want to Walk
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2020-08-14 23:40:49
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 373 ms / 2,000 ms
コード長 1,562 bytes
コンパイル時間 1,275 ms
コンパイル使用メモリ 126,388 KB
実行使用メモリ 7,808 KB
最終ジャッジ日時 2024-04-18 23:19:48
合計ジャッジ時間 7,768 ms
ジャッジサーバーID
(参考情報)
judge1 / 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 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 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 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 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 3 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 361 ms
7,680 KB
testcase_28 AC 362 ms
7,552 KB
testcase_29 AC 373 ms
7,680 KB
testcase_30 AC 368 ms
7,680 KB
testcase_31 AC 360 ms
7,808 KB
testcase_32 AC 361 ms
7,552 KB
testcase_33 AC 359 ms
7,680 KB
testcase_34 AC 367 ms
7,808 KB
testcase_35 AC 370 ms
7,680 KB
testcase_36 AC 357 ms
7,680 KB
testcase_37 AC 365 ms
7,680 KB
testcase_38 AC 372 ms
7,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

struct unionfind {
    vector<long long> par,_size;
    unionfind(long n) : par(n+1), _size(n+1,1) {
        for(long long i=0; i<n; i++) par[i]=i;
    }
    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]);
    }
    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);
        _size[x] += _size[y];
        par[y] = x;
        return true;
    }
    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();
        imos[lindex]++;
        imos[rindex-1]--;
        uni.merge(i, lindex);
    }

    for (int i=0; i<n-1; i++) imos[i+1] += imos[i];
    for (int i=0; i<n-1; i++) if(imos[i]>0) uni.merge(i,i+1);

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