結果

問題 No.1170 Never Want to Walk
ユーザー chocobochocobo
提出日時 2020-08-14 21:35:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 358 ms / 2,000 ms
コード長 2,105 bytes
コンパイル時間 1,343 ms
コンパイル使用メモリ 130,468 KB
実行使用メモリ 7,644 KB
最終ジャッジ日時 2024-04-18 21:11:31
合計ジャッジ時間 7,263 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 4 ms
6,940 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 4 ms
6,940 KB
testcase_18 AC 4 ms
6,940 KB
testcase_19 AC 4 ms
6,944 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 3 ms
6,940 KB
testcase_22 AC 4 ms
6,944 KB
testcase_23 AC 4 ms
6,944 KB
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 4 ms
6,944 KB
testcase_26 AC 4 ms
6,944 KB
testcase_27 AC 343 ms
7,576 KB
testcase_28 AC 338 ms
7,400 KB
testcase_29 AC 346 ms
7,512 KB
testcase_30 AC 344 ms
7,500 KB
testcase_31 AC 347 ms
7,416 KB
testcase_32 AC 341 ms
7,576 KB
testcase_33 AC 340 ms
7,400 KB
testcase_34 AC 344 ms
7,644 KB
testcase_35 AC 346 ms
7,620 KB
testcase_36 AC 335 ms
7,548 KB
testcase_37 AC 342 ms
7,436 KB
testcase_38 AC 358 ms
7,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;


#define REP(i, n) for(ll i = 0; i < n; i++)





























class Unionfind {
private:
    vector<int> par;
    vector<int> rank;
    vector<int> counter;
    
public:
    Unionfind(int n) : rank(n), counter(n, 1){
        for(int i = 0; i < n; i++){
            par.push_back(i);
        }
    }
    
    int find(int x){
        if (par[x] == x) {
            return x;
        }
        else {
            return par[x] = find(par[x]);
        }
    }
    
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if (x == y) return;
        
        if (rank[x] < rank[y]) {
            counter[y] += counter[x];
            counter[x] = counter[y];
            par[x] = y;
        }
        else {
            counter[y] += counter[x];
            counter[x] = counter[y];
            par[y] = x;
            if (rank[x] == rank[y]) {
                rank[x]++;
            }
        }
    }
    
    bool same(int x, int y){
        return find(x) == find(y);
    }
    
    ll count(int x){
        return counter[find(x)];
    }
};

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> x(n);
    REP(i, n){
        cin >> x[i];
    }
    Unionfind uni(n);
    REP(i, n){
        ll itr1 = lower_bound(x.begin() + i, x.end(), x[i] + a) - x.begin();
        ll itr2 = --lower_bound(x.begin() + i, x.end(), x[i] + b + 1) - x.begin();
        while(itr1 < n && itr2 >= 0 && x[itr1] <= x[itr2] && !uni.same(i, itr2)){
            uni.unite(i, itr2);
            itr2--;
        }
    }
    REP(i, n){
        cout << uni.count(i) << endl;
    }
}
0