結果

問題 No.1170 Never Want to Walk
ユーザー carrot46carrot46
提出日時 2020-08-14 22:18:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 419 ms / 2,000 ms
コード長 2,109 bytes
コンパイル時間 2,067 ms
コンパイル使用メモリ 173,312 KB
実行使用メモリ 17,560 KB
最終ジャッジ日時 2024-04-18 22:09:13
合計ジャッジ時間 8,492 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 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 3 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 4 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 4 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 405 ms
16,756 KB
testcase_28 AC 395 ms
16,568 KB
testcase_29 AC 419 ms
17,120 KB
testcase_30 AC 417 ms
16,952 KB
testcase_31 AC 404 ms
16,844 KB
testcase_32 AC 389 ms
17,008 KB
testcase_33 AC 373 ms
16,696 KB
testcase_34 AC 394 ms
17,372 KB
testcase_35 AC 390 ms
17,208 KB
testcase_36 AC 392 ms
16,844 KB
testcase_37 AC 389 ms
16,744 KB
testcase_38 AC 393 ms
17,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);


int main(){
    class union_find{
            vector<long> parent, tree_size;
    public:
            union_find(unsigned long _n) : parent(_n), tree_size(_n, 1){
                for(unsigned long i = 0; i < _n; ++i)parent[i] = i;
            }
            ll find(ll x){
                while(parent[x] != x)x = parent[x] = parent[parent[x]];
                return x;
            }
            void merge(ll a, ll b){
                a = find(a);
                b = find(b);
    	    if(a==b) return;
                if(tree_size[a] < tree_size[b])swap(a, b);
                tree_size[a] += tree_size[b];
                parent[b] = a;
                return;
            }
    	bool same(ll a, ll b){
    	    a = find(a);
    	    b = find(b);
    	    return a == b;
    	}
    	ll get_size(ll a){
                return tree_size[find(a)];
            }
        };
    //uf.mergeのように使う
    //ufはMAX_N+1でとるか、代入時に0-indexedにする
    cin>>N>>A>>B;
    union_find uf(N + 10);
    vec a(N);
    rep(i,N) cin>>a[i];
    a.push_back(ll(3e+9));
    set<int> valid;
    rep(i,N + 1) valid.insert(i);
    int l = 0;
    auto ite_r = valid.begin();
    ++ite_r;
    auto last = ite_r;
    while(l < N){
        if(a[*ite_r] - a[l] < A){
            last = ++ite_r;
        }else if(a[*ite_r] - a[l] <= B){
            uf.merge(l, *ite_r);
            if(last != ite_r) valid.erase(last);
            last = ite_r++;
        }else{
            ++l;
            ite_r = valid.lower_bound(l + 1);
            last = ite_r;
        }
    }
    rep(i,N){
        cout<<uf.get_size(i)<<endl;
    }
}
0