結果

問題 No.1170 Never Want to Walk
ユーザー tyaro804tyaro804
提出日時 2020-08-15 13:51:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 365 ms / 2,000 ms
コード長 1,578 bytes
コンパイル時間 1,862 ms
コンパイル使用メモリ 166,532 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 01:05:40
合計ジャッジ時間 7,871 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 4 ms
6,944 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 4 ms
6,944 KB
testcase_15 AC 4 ms
6,940 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 3 ms
6,944 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 AC 4 ms
6,944 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 3 ms
6,944 KB
testcase_22 AC 4 ms
6,944 KB
testcase_23 AC 3 ms
6,944 KB
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 3 ms
6,944 KB
testcase_26 AC 4 ms
6,940 KB
testcase_27 AC 352 ms
6,940 KB
testcase_28 AC 354 ms
6,940 KB
testcase_29 AC 356 ms
6,944 KB
testcase_30 AC 356 ms
6,940 KB
testcase_31 AC 351 ms
6,940 KB
testcase_32 AC 355 ms
6,940 KB
testcase_33 AC 349 ms
6,940 KB
testcase_34 AC 359 ms
6,940 KB
testcase_35 AC 354 ms
6,944 KB
testcase_36 AC 348 ms
6,940 KB
testcase_37 AC 343 ms
6,940 KB
testcase_38 AC 365 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

struct UnionFind{
    vector<int> d;
    UnionFind(int n = 0): d(n, -1){}
    int find(int x){
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y){
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) {return find(x) == find(y);}
    int size(int x){return -d[find(x)];}
};

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> x(n);
    rep(i,n) cin >> x[i];

    UnionFind uf(n);
    vector<int> y(n);
    rep(i,n){
        int l = lower_bound(all(x), x[i]+a) - x.begin();
        int r = (upper_bound(all(x), x[i]+b) - x.begin()) - 1;
        if (l > r) continue;
        uf.unite(i, l);
        y[l]++;
        y[r]--;
    }

    rep(i,n-1) y[i+1] = y[i+1] + y[i];
    rep(i,n-1) if (y[i] > 0) uf.unite(i, i+1);

    rep(i,n){
        cout << uf.size(i) << endl;
    }
    return 0;
}
0