結果

問題 No.1170 Never Want to Walk
ユーザー NNMochiNNMochi
提出日時 2020-08-15 15:47:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 311 ms / 2,000 ms
コード長 2,444 bytes
コンパイル時間 2,199 ms
コンパイル使用メモリ 170,000 KB
実行使用メモリ 8,700 KB
最終ジャッジ日時 2024-04-19 01:15:48
合計ジャッジ時間 7,872 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 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 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 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 300 ms
8,392 KB
testcase_28 AC 300 ms
8,496 KB
testcase_29 AC 309 ms
8,680 KB
testcase_30 AC 308 ms
8,540 KB
testcase_31 AC 299 ms
8,508 KB
testcase_32 AC 297 ms
8,644 KB
testcase_33 AC 296 ms
8,500 KB
testcase_34 AC 310 ms
8,680 KB
testcase_35 AC 308 ms
8,664 KB
testcase_36 AC 299 ms
8,508 KB
testcase_37 AC 298 ms
8,512 KB
testcase_38 AC 311 ms
8,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

template <typename T>
bool chmax(T &a, const T& b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}
struct UnionFind {
    vector<int> par;
    vector<int> rnk;
    vector<int> siz;
    UnionFind(int N):par(N),rnk(N),siz(N){
        for (int i=0;i<N;i++){
            par[i]=i,rnk[i]=0,siz[i]=1;
        }
    }
    //根
    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }
    void unite(int x,int y){
        int rx=find(x);
        int ry=find(y);
        if (rx==ry) return;
        if(rnk[rx]<rnk[ry]){
            par[rx]=ry;
            siz[ry]+=siz[rx];
            siz[rx]=0;
        }
        else{
            par[ry]=rx;
            siz[rx]+=siz[ry];
            siz[ry]=0;
            if(rnk[rx]==rnk[ry]){
                rnk[rx]++;
            }
        }
    }
    //集合が同じか
    bool same(int x,int y){
        return find(x)==find(y);
    }
    //集合の大きさ
    int size(int x){
        return siz[find(x)];
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,A,B;
    cin >> N >> A >> B;
    vl X(N);
    rep(i,N){
        cin >> X[i];
    }
    X.pb(INF);
    UnionFind uf(N);
    vl d(N,0);
    rep(i,N){
        int l=lower_bound(X.begin(),X.end(),X[i]+A)-X.begin();
        int r=upper_bound(X.begin(),X.end(),X[i]+B)-X.begin()-1;
        if(l>r)continue;
        uf.unite(i,l);
        d[l]++;d[r]--;
    }
    rep(i,N-1){
        d[i+1]=d[i]+d[i+1];
    }
    rep(i,N-1){
        if(d[i]>0){
            uf.unite(i,i+1);
        }
    }
    rep(i,N){
        cout << uf.size(i) << endl;
    }
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/
0