結果

問題 No.1170 Never Want to Walk
ユーザー ShibuyapShibuyap
提出日時 2020-08-15 05:18:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 345 ms / 2,000 ms
コード長 1,549 bytes
コンパイル時間 2,348 ms
コンパイル使用メモリ 198,952 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2023-08-01 00:44:31
合計ジャッジ時間 9,057 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,732 KB
testcase_01 AC 3 ms
5,656 KB
testcase_02 AC 3 ms
5,644 KB
testcase_03 AC 3 ms
5,752 KB
testcase_04 AC 3 ms
5,656 KB
testcase_05 AC 3 ms
5,660 KB
testcase_06 AC 3 ms
5,696 KB
testcase_07 AC 3 ms
5,676 KB
testcase_08 AC 3 ms
5,720 KB
testcase_09 AC 3 ms
5,672 KB
testcase_10 AC 3 ms
5,696 KB
testcase_11 AC 3 ms
5,680 KB
testcase_12 AC 5 ms
5,676 KB
testcase_13 AC 5 ms
5,700 KB
testcase_14 AC 5 ms
5,792 KB
testcase_15 AC 5 ms
5,660 KB
testcase_16 AC 5 ms
5,708 KB
testcase_17 AC 5 ms
5,680 KB
testcase_18 AC 5 ms
5,960 KB
testcase_19 AC 5 ms
5,828 KB
testcase_20 AC 5 ms
5,668 KB
testcase_21 AC 5 ms
5,668 KB
testcase_22 AC 5 ms
5,656 KB
testcase_23 AC 5 ms
5,700 KB
testcase_24 AC 5 ms
5,660 KB
testcase_25 AC 5 ms
5,792 KB
testcase_26 AC 4 ms
5,952 KB
testcase_27 AC 330 ms
6,400 KB
testcase_28 AC 321 ms
6,416 KB
testcase_29 AC 338 ms
6,524 KB
testcase_30 AC 337 ms
6,548 KB
testcase_31 AC 322 ms
6,428 KB
testcase_32 AC 323 ms
6,448 KB
testcase_33 AC 325 ms
6,420 KB
testcase_34 AC 335 ms
6,424 KB
testcase_35 AC 331 ms
6,460 KB
testcase_36 AC 323 ms
6,436 KB
testcase_37 AC 326 ms
6,404 KB
testcase_38 AC 345 ms
6,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}

const int MAX_N = 200100;
int par[MAX_N]; // 親
int rank_[MAX_N]; // 木の深さ
int cnt_[MAX_N]; // 属する頂点の個数(親のみ正しい)

// n要素で初期化
void UFinit(){
    for(int i=0;i<MAX_N;i++){
        par[i] = i;
        rank_[i] = 0;
        cnt_[i] = 1;
    }
}

// 木の根を求める
int find(int x){
    if(par[x] == x){
        return x;
    }else{
        return par[x] = find(par[x]);
    }
}

// xとyの属する集合を併合
void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rank_[x] < rank_[y]){
        par[x] = y;
        cnt_[y] += cnt_[x];
    }else{
        par[y] = x;
        cnt_[x] += cnt_[y];
        if(rank_[x] == rank_[y]) rank_[x]++;
    }
}

// xとyが同じ集合に属するか否か
bool same(int x, int y){
    return find(x) == find(y);
}


int main() {
    UFinit();
    int n, a, b;
    cin >> n >> a >> b;
    int x[n];
    rep(i,n)cin >> x[i];

    int l = 0, r = 0;

    rep(i,n){
        while(l<n&&x[l]<x[i]+a)l++;
        if(l==n)break;
        r = max(r,l);
        if(x[l]<=x[i]+b)unite(i,l);
        while(r+1<n&&x[r+1]<=x[i]+b){
            unite(l,r+1);
            r++;
        }
    }

    rep(i,n) cout << cnt_[find(i)] << endl;
    return 0;
}

0