結果

問題 No.1170 Never Want to Walk
ユーザー ningenMeningenMe
提出日時 2020-08-15 03:54:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 381 ms / 2,000 ms
コード長 2,466 bytes
コンパイル時間 2,662 ms
コンパイル使用メモリ 204,480 KB
実行使用メモリ 15,924 KB
最終ジャッジ日時 2024-04-18 23:36:06
合計ジャッジ時間 8,563 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 4 ms
6,940 KB
testcase_14 AC 4 ms
6,940 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 4 ms
6,940 KB
testcase_19 AC 4 ms
6,940 KB
testcase_20 AC 4 ms
6,944 KB
testcase_21 AC 3 ms
6,940 KB
testcase_22 AC 3 ms
6,944 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 4 ms
6,940 KB
testcase_26 AC 4 ms
6,944 KB
testcase_27 AC 314 ms
15,172 KB
testcase_28 AC 308 ms
15,152 KB
testcase_29 AC 322 ms
15,080 KB
testcase_30 AC 325 ms
15,700 KB
testcase_31 AC 315 ms
14,908 KB
testcase_32 AC 362 ms
15,716 KB
testcase_33 AC 369 ms
15,160 KB
testcase_34 AC 369 ms
15,716 KB
testcase_35 AC 379 ms
15,064 KB
testcase_36 AC 378 ms
15,724 KB
testcase_37 AC 371 ms
15,172 KB
testcase_38 AC 381 ms
15,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

//Union Find Tree
class UnionFindTree {
	vector<int> parent,maxi,mini;
	inline int root(int n) {
        return (parent[n]<0?n:parent[n] = root(parent[n]));
	}
public:
    UnionFindTree(int N = 1) : parent(N,-1),maxi(N),mini(N){
        iota(maxi.begin(),maxi.end(),0);
        iota(mini.begin(),mini.end(),0);
	}
    inline bool connected(int n, int m) {
		return root(n) == root(m);
	}
	inline void merge(int n, int m) {
		n = root(n);
		m = root(m);
		if (n == m) return;
		if(parent[n]>parent[m]) swap(n, m);
        parent[n] += parent[m];
        parent[m] = n;
        maxi[n] = std::max(maxi[n],maxi[m]);
        mini[n] = std::min(mini[n],mini[m]);
	}
    inline int min(int n) {
        return mini[root(n)];
    }
    inline int max(int n) {
        return maxi[root(n)];
    }
    inline int size(int n){
        return (-parent[root(n)]);
    }
    inline int operator[](int n) {
		return root(n);
	}
    inline void print() {
        for(int i = 0; i < parent.size(); ++i) cout << root(i) << " ";
        cout << endl;
    }
};

class RangeIndex{
    int length;
public:
    RangeIndex(const int N) {
        for (length = 1; length <= N; length *= 2);
    }
    //[l,r)
    vector<int> range(int l,int r) {
        vector<int> res;
        for(l += length, r += length; l < r; l >>=1, r >>=1) {
            if(l&1) res.push_back(l++);
            if(r&1) res.push_back(--r);
        }
        return res;
    }
    inline int operator[](int idx) {
		return idx+length;
	}
    inline size_t size(void){
        return length;
    }
};


int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    long long N,A,B; cin >> N >> A >> B;
    vector<long long> X(N);
    for(int i = 0; i < N; ++i) cin >> X[i];
    X.push_back(1e10);
    RangeIndex ri(N);
    UnionFindTree uf(2*ri.size());
    vector<int> st(2*ri.size(),0);
    for(int i = 0; i < N; ++i) {
        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();
        for(auto& e:ri.range(l,r)) {
            st[e]=1;
            uf.merge(ri[i],e);
        }
    }
    for(int i = 0; i < N; ++i) {
        int j=i+ri.size();
        while(j >>= 1) if(st[j]) uf.merge(ri[i],j);
    }
    vector<int> cnt(2*ri.size(),0);
    for(int i = 0; i < N; ++i) {
        cnt[uf[ri[i]]]++;
    }
    for(int i = 0; i < N; ++i) {
        cout << cnt[uf[ri[i]]] << endl;
    }

    return 0;
}
0