結果

問題 No.1170 Never Want to Walk
ユーザー hs0319boyhs0319boy
提出日時 2020-08-15 06:48:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 362 ms / 2,000 ms
コード長 1,999 bytes
コンパイル時間 1,719 ms
コンパイル使用メモリ 168,496 KB
実行使用メモリ 6,656 KB
最終ジャッジ日時 2024-04-18 23:40:23
合計ジャッジ時間 8,082 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,376 KB
testcase_01 AC 4 ms
5,760 KB
testcase_02 AC 3 ms
5,504 KB
testcase_03 AC 4 ms
5,632 KB
testcase_04 AC 4 ms
5,632 KB
testcase_05 AC 3 ms
5,504 KB
testcase_06 AC 3 ms
5,504 KB
testcase_07 AC 4 ms
5,632 KB
testcase_08 AC 4 ms
5,504 KB
testcase_09 AC 4 ms
5,504 KB
testcase_10 AC 3 ms
5,504 KB
testcase_11 AC 3 ms
5,632 KB
testcase_12 AC 5 ms
5,760 KB
testcase_13 AC 5 ms
5,760 KB
testcase_14 AC 5 ms
5,632 KB
testcase_15 AC 5 ms
5,632 KB
testcase_16 AC 5 ms
5,632 KB
testcase_17 AC 5 ms
5,632 KB
testcase_18 AC 5 ms
5,760 KB
testcase_19 AC 5 ms
5,632 KB
testcase_20 AC 5 ms
5,504 KB
testcase_21 AC 5 ms
5,504 KB
testcase_22 AC 5 ms
5,760 KB
testcase_23 AC 5 ms
5,632 KB
testcase_24 AC 5 ms
5,760 KB
testcase_25 AC 5 ms
5,632 KB
testcase_26 AC 5 ms
5,760 KB
testcase_27 AC 362 ms
6,528 KB
testcase_28 AC 353 ms
6,272 KB
testcase_29 AC 362 ms
6,528 KB
testcase_30 AC 358 ms
6,400 KB
testcase_31 AC 358 ms
6,528 KB
testcase_32 AC 356 ms
6,400 KB
testcase_33 AC 359 ms
6,272 KB
testcase_34 AC 356 ms
6,656 KB
testcase_35 AC 353 ms
6,400 KB
testcase_36 AC 349 ms
6,400 KB
testcase_37 AC 346 ms
6,400 KB
testcase_38 AC 359 ms
6,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int MAX_N=2e5+20;

vin par(MAX_N);
vin deep(MAX_N);
vin sizee(MAX_N);
void init(int n);
int root(int x);
void unite(int x,int y);
bool same(int x,int y);
int group_size(int x);

int main(){
    int n,a,b;cin>>n>>a>>b;
    vin x(n);rep(i,n)cin>>x[i];
    vbo already(n,false);
    init(n);
    int l,r;
    rep(i,n){
        already[i]=true;
        l=lower_bound(all(x),x[i]+a)-x.begin();
        r=upper_bound(all(x),x[i]+b)-x.begin();
        for(int j=r-1;j>=l;j--){
            if(!already[j]){
                unite(i,j);
                already[j]=true;
            }
            else{
                unite(i,j);
                break;//l~j-1とjはすでにつながっている
            }
        }
    }
    rep(i,n)cout<<group_size(i)<<endl;
}

void init(int n){
    rep(i,n+1){
        par[i]=i;
        deep[i]=0;
        sizee[i]=1;
    }
}
int root(int x){
    if(par[x]==x)return x;
    else return par[x]=root(par[x]);
}
void unite(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y)return;
    if(deep[x]<deep[y]){
        par[x]=y;
        sizee[y]+=sizee[x];
    }
    else{
        par[y]=x;
        sizee[x]+=sizee[y];
        if(deep[x]==deep[y])deep[x]++;
    }
}
bool same(int x,int y){
    return root(x)==root(y);
}
int group_size(int x){
    return sizee[root(x)];
}
0